Skip to main content

An etree utility package

Project description

dynamicxml

A simple extension of Etree that gives users the ability to directly access attributes and nodes without having to implement boilerplate python code.

Rationale for this library: Dynamic XML Library with Python

DynamicElement is a drop-in replacement for any Etree code that you already have

<!-- ConfigFile.xml -->
<ConfigurationData>
    <Runtime timeout="1000" runtimeDataPath="/path/to/runtime/data" />
</ConfigurationData>
# main.py
import dynamicxml

# parse the data and get back an instance of DynamicElement
root = dynamicxml.parse('data/ConfigFile.xml')

# Print the tag of the root element, just like you would a typical etree
# element
print (root.tag)

# get access to the runtime data node, which is a child of
# <ConfigurationData />.  The library returns a list of child
# nodes, regardless of how many elements there are.  An "AttributeError"
# is raised if the node does not exist.
runtimeNode = root.Runtime[0]

# Access the attributes of the node directly using the "attr_" prefix.
print (runtimeNode.attr_timeout)
print (runtimeNode.attr_runtimeDataPath)

# set the data directly
runtimeNode.attr_timeout = str(int(runtimeNode.attr_timeout) + 1)

# easy writing of the data
dynamicxml.write('data/ConfigFile_Updated.xml', root)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

dynamicxml-1.1-py3-none-any.whl (4.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page