Registry / serialization / jxmlease

jxmlease

JSON →
library1.0.3pypypi✓ verified 85d ago

jxmlease is a Python library designed for seamless conversion between XML documents and intelligent Python data structures. It aims to simplify XML processing by representing XML data and its metadata (like attributes) using extended Python list, dictionary, and string types. The current version is 1.0.3, with releases focusing on bug fixes and minor enhancements.

pip install jxmlease
INSTALL
IMPORT
SIG · JXMLEASE
J
jxmlease
serializationpythonv1.0.3
Install
1.5s avg
Import
191ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.201s · 18MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.5s · import 0.181s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse
from jxmlease import parse
import jxmlease; jxmlease.Parser().parse(xml_string)
The top-level `parse` function is a convenient shortcut for `jxmlease.Parser().parse()`.
emit_xml
from jxmlease import emit_xml
import jxmlease; jxmlease.XMLDictNode(data_structure).emit_xml()
The top-level `emit_xml` function was introduced in v1.0.1 for direct conversion from Python data structures to XML, simplifying output.
XMLDictNode
from jxmlease import XMLDictNode
Used for converting Python dictionaries to jxmlease's intelligent XML dictionary nodes for more control.

This quickstart demonstrates parsing an XML string into a Python data structure, accessing elements and attributes, and converting a Python dictionary back into an XML string using the `parse` and `emit_xml` top-level functions. For more granular control over XML node creation, `XMLDictNode` and `XMLListNode` can be used directly.

import jxmlease xml_string = """<root><item id="1">Value 1</item><item id="2">Value 2</item></root>""" # Parse XML to Python data structure data_structure = jxmlease.parse(xml_string) print("Parsed Data Structure:") print(data_structure.prettyprint()) # Accessing data and attributes print(f"\nFirst item value: {data_structure['root']['item'][0].value}") print(f"First item ID: {data_structure['root']['item'][0].get_xml_attr('id')}") # Convert Python data structure to XML python_data = { 'catalog': { 'book': [ {'@id': 'bk101', 'author': 'Gambardella, Matthew', 'title': 'XML Developer's Guide'}, {'@id': 'bk102', 'author': 'Ralls, Kim', 'title': 'Midnight Rain'} ] } } # Using emit_xml (available since v1.0.1) output_xml = jxmlease.emit_xml(python_data) print("\nEmitted XML:") print(output_xml)
Debug
Known issues
gotchaStandard library's ElementTree does not maintain original XML namespace identifiers. If namespace fidelity is critical during parsing and iteration, consider installing `lxml`.
fix
Install `lxml` (`pip install lxml`) and `jxmlease` will automatically leverage its advanced functionality for improved namespace handling.
affects: All versions
gotchaWhen parsing XML with mixed element types that are expected to maintain a specific order (e.g., `<foo><a>one</a><b>two</b><a>three</a></foo>`), `jxmlease` might reorder siblings of different tags during conversion to Python dicts, leading to incorrect XML output if re-emitted. This is due to its dictionary-centric representation.
fix
For applications where child order of mixed tags is strictly semantic, `jxmlease` might require post-processing of the Python structure or a different XML library. Or, ensure consistent tag usage for siblings if order is important.
affects: All versions, specifically 1.0.1 through 1.0.3
gotchaXML output generated from Python data structures with explicit namespaces (e.g., `{'soapenv:Envelope xmlns:foo':'...'}`) may incorrectly include namespace declarations on *both* opening and closing tags, which is not standard compliant and can break other XML parsers.
fix
This is an open issue. For critical use cases requiring perfectly formatted namespace output, manual post-processing of the XML string may be necessary, or consider alternatives for XML emission if this behavior is observed.
affects: All versions, specifically 1.0.1 through 1.0.3
Errors
Common errors & fixes
KeyError: 'attribute_name'
Attempting to access an XML attribute directly using `node.get_xml_attr('attribute_name')` when the attribute does not exist on the node, and no default value was provided.
fix
Use `node.get_xml_attr('attribute_name', default_value)` to provide a fallback, or check for attribute existence before accessing: `if 'attribute_name' in node.xml_attrs: ...`.
AttributeError: If the node is out of date.
Trying to modify an `XMLNodeBase` instance (e.g., `append_cdata()`, `delete_xml_attr()`, `set_xml_attr()`) that is no longer a valid, current reference within the parsed XML tree, typically after other structural modifications have occurred.
fix
Always operate on the most recently returned or explicitly retrieved `XMLNodeBase` object. If modifications are intertwined, use `node.get_current_node()` to ensure you have an up-to-date reference before applying further changes.
Upgrade
Version history
1.0.3latest on PyPI · released May 29, 2020
Audit
Dependencies
lxmloptionalOptional dependency for enhanced namespace handling and ElementTree parsing; standard ElementTree (built-in) is sufficient for basic functionality.
Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
jxmlease — pip install jxmlease · libregistry