# μXML - xml stream parsing in less than 100 lines of code
μXML is oversimlified way to parse large (or slow loading) XML lines with easy way for tag matching and callbacking. No dependencies (besides python3.4+) and only one class uxml.Parser inside the library.
`python import uxml p = uxml.Parser(open('test.rss')) p.find('/rss/channel/item', lambda e: print(e)) p.start() `
First meaningful line is parser’s object creation. The only parameter is file (or any other io.TextIOWrapper compatible) object. .find method add new tag matcher for parser. First argument is a pointer to tag which we want to find inside xml stream. I use nanoxpath notation (i.e. you should show full path to this tags or use // as a starting symbol). Second argument of find is a callback which will be invoked if given tag is found and the only argument for this callback is a internal structure of tags and attributes inside this tag. Attributes can be separated from children tags by name, it’s always starts with ‘@’ symbol. If tag is just one internal text - it will be returned as result. If there’s more than one children with same name, it will be returned as list of tags. If tag have both internal text and attributes, first will be added to attributes as ‘#text’.
You can use unlimited number of find’s. Parsing will start with start method. Example above will print every item inside given rss file. Let me show you a little bit more complicated stuff.
`python res = [] p = uxml.Parser('test.rss') p.find('//link', lambda x: res.append(x)).find('//description', lambda x: print(x)).start() `
First off all you can notice what find and start calls are chainable. Trailing / will convert to any number of previous tags, so this time we will got list of links at res variable. Also we just pass ‘test.rss’ filename to Parser constructor. It’s not only open this file but also trying to guess XML encoding (very poorly but anyway).
Metadata
Release files for uxml 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| uxml-0.3.0.tar.gz | 3.6 kB | Without provenance | Details for uxml-0.3.0.tar.gz |
Release files / uxml-0.3.0.tar.gz
| Download URL | uxml-0.3.0.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
76e7d755e03b74b127b3a460c6e28dea96b61caa3fff3e879d302e784923ceb7
|
|
BLAKE2b-256 checksum How to use checksums |
9354c9fdb746cd474f46b61b0f0ba6aad8fa906fed10243e22c67b6228e79e89
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for uxml 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.