xml-python

0.4.3 · maintenance · verified Sun Apr 12

xml-python is a library for making Python objects from XML, designed to parse XML nodes using decorated functions. Last updated in January 2021 (v0.4.3), the project appears to be unmaintained with no public documentation beyond its minimal PyPI description.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a Python object that maps to an XML structure using `xml-python`'s decorator-based parsing. It defines a `MyNodeObject` class and a `parse_root` function decorated to handle the 'root' XML tag, extracting data from its 'title' and 'text' child nodes.

from xml_python import xml_objects

xml_data = """
<root>
  <title>This is a title</title>
  <text>This is some text</text>
</root>
"""

# Define a Python class to represent your XML structure
class MyNodeObject(xml_objects.XMLObject):
    pass

# Use a decorator to associate the parser function with the 'root' tag
@xml_objects.node_parser(MyNodeObject, 'root')
def parse_root(parser, node):
    # Extract data from child nodes
    parser.title = node.find('title').text
    parser.text = node.find('text').text

# Parse the XML string into the Python object
root_object = xml_objects.parse_string(xml_data)

print(f"Parsed Title: {root_object.title}")
print(f"Parsed Text: {root_object.text}")

view raw JSON →