Skip to content

claybrooks/dynamic-xml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Pip Installer: pip

python -m pip install dynamicxml

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)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages