Comprehensive XML generator for Python
Project description
XML Generator
Comprehensive XML generator for Python
Table of Contents
Installation
pip install xml-generator
Usage
Import
from xml_generator.types import XmlNode
Comprehensive parsing
Parse Comprehensive format into an XmlNode object.
node = XmlNode.parse(
{
"name": "node",
"attributes": {"attr1": "value1", "attr2": "value2"},
"body": [
{"name": "child1", "attributes": {"attr1": "value1"}},
{"name": "child2", "attributes": {"attr2": "value2"}},
],
}
)
Parse Comprehensive format with quries
node = XmlNode.from_query('node@attr1="value1"@attr2="value2"')
nodes = XmlNode.from_queries(
[
"NoValueNode",
{
"SHORT-NAME": "node",
},
{
"ELEMENTS@type='string'": [
"element@hint='id'",
"element@unit='m'",
{"element@unit='m'@min='0'@max='100'@init='50'": "100"},
],
},
]
)
Searching a specific node
Return the first XmlNode with the given query. Query can be a name with attributes.
parent = node.find("node")
child1 = node.find("child1@attr1")
child2 = node.find("child2")
Generate a xml file
Using the to_xml()
function that return the XmlNode as an XML string.
with open('sample.xml', 'w', encoding='utf-8') as f:
f.write(node.to_xml())
Contributing
Coming soon.
Testing
python -m unittest discover -s xml_generator/tests -p "test*.py"
Building
python .\setup.py sdist bdist_wheel
Deployment
twine upload dist/*
License
License :: OSI Approved :: MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for xml-generator-seobaeksol-0.2.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e9095c3be7c355b0cc49440250faf7f93620575c7130df0216643aee1418995 |
|
MD5 | 9945e0648a53e091cd4a74321a6eabc5 |
|
BLAKE2b-256 | a764172db38a0b33b34b745020bc037516a4d63ff557b4ad889a9d7fd848aeb4 |
Close
Hashes for xml_generator_seobaeksol-0.2.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1635792bf463aeeba664ffd06a28449b78a3f41bc76382f6f2b80693458d2b45 |
|
MD5 | 21901d0ce10b42f8fd62088750f7b5b8 |
|
BLAKE2b-256 | 18b2d3038e99575fdf5c2d33212921fa66eefd634b121de11d6c989c0d2a5d4f |