Welcome to jxmlease: a Python module for converting XML to intelligent Python data structures, and converting Python data structures to XML.
What is jxmlease?
Do you have a requirement to process XML data, but find it cumbersome to process XML data in Python? If so, you are not alone.
The main problem with processing XML data in Python is that it doesn’t map well to native Python data structures. XML contains both data and metadata, while native Python objects (lists, dictionaries, and strings) only contain data.
But, wait! That’s not completely true. Actually, Python objects do have the ability to hold metadata. jxmlease subclasses Python list, dictionary, and string types to create new, smart XML classes that can represent the XML data as normal Python objects while also maintaining the metadata for you to use.
For example, consider this sample XML document:
<a>
<b>
<z changed="true">foo</z>
</b>
<c>
<d>
<z changed="true">bar</z>
</d>
</c>
<e>
<z>baz</z>
</e>
</a>
Using jxmlease, you can get a standard Python representation of the data in this XML document:
>>> root = jxmlease.parse(xml)
>>> root.prettyprint()
{u'a': {u'b': {u'z': u'foo'},
u'c': {u'd': {u'z': u'bar'}},
u'e': {u'z': u'baz'}}}
You can also still access the metadata:
>>> root['a']['b']['z'].get_xml_attr("changed")
u'true'
jxmlease also provides flexibility for parsing your data. If you only need select information from your XML data, you can have jxmlease return it while it is parsing the document:
>>> for path, _, node in jxmlease.parse(xml, generator="z"):
... changed = node.get_xml_attr("changed", None) is not None
... print("%-8s: %s %s" % (path, node, "(changed)" if changed else ""))
...
/a/b/z : foo (changed)
/a/c/d/z: bar (changed)
/a/e/z : baz
You can also iterate over the full, parsed document:
>>> for node in root.find_nodes_with_tag("z"):
... changed = node.get_xml_attr("changed", None) is not None
... print("%s %s" % (node, "(changed)" if changed else ""))
...
foo (changed)
bar (changed)
baz
These iterations can even return part of an XML tree:
>>> for node in root.find_nodes_with_tag(("b", "c")):
... print("<%s>: %s" % (node.tag, node))
...
<b>: {u'z': u'foo'}
<c>: {u'd': {u'z': u'bar'}}
And, importantly, these objects are subclasses of Python objects, so things like string comparisons work correctly:
>>> root['a']['b']['z'] == "foo" True >>> root['a']['b']['z'] == "bar" False
We think that these features, and others, combine to ease XML processing in Python: hence, the name: jxmlease.
Documentation
The documentation is hosted on readthedocs.
Installation
See the installation instructions. for more information on installing jxmlease.
Metadata
Release files for jxmlease 1.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 |
|---|---|---|---|---|
| jxmlease-1.0.tar.gz | 47.6 kB | Without provenance | Details for jxmlease-1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| jxmlease-1.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for jxmlease-1.0-py2.py3-none-any.whl |
Total release size: 84.4 kB
Release files / jxmlease-1.0.tar.gz
| Download URL | jxmlease-1.0.tar.gz |
|---|---|
| Size | 47.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
256da0377f8276d55b91adc2640f02569422cfa4bc8eef60eee1b3f73444d577
|
|
BLAKE2b-256 checksum How to use checksums |
316220a8925498fa9174eeb4ba2cbbeb6f043ac74035f086bcd967c7a8e88e43
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / jxmlease-1.0-py2.py3-none-any.whl
| Download URL | jxmlease-1.0-py2.py3-none-any.whl |
|---|---|
| Size | 36.8 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
9f8e9fbd7a205e3ef61dbf7654acfe439b19f954cec421a8869572ddff91ded6
|
|
BLAKE2b-256 checksum How to use checksums |
d37b596ddc42542eecec8dea5c864d6428bcf5f4e85c219bd42bb3d2989fd654
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for jxmlease 1.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.