jxmlease

1.0.3 · active · verified Thu Apr 16

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.

Common errors

Warnings

Install

Imports

Quickstart

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)

view raw JSON →