Comprehensive XML generator for Python
Project description
XML Generator
Comprehensive XML generator for Python
Table of Contents
Installation
pip install xml-generator-seobaeksol
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"}},
],
}
)
Create a XmlNode with a query
node = XmlNode.from_query('node@attr1="value1"@attr2="value2"')
Create a XmlNode with a extended query
extend_query = {
"root": [
"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")
Serialization
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())
Using the to_extend_query() function that return the extended query object as an XML string.
extended_query_obj = root.to_extended_query()
Deserialization
Use XmlParser class for reading a xml file that return XmlNode by close() method.
It is sub-class of xml.etree.ElementTree.XMLParser built-in python class.
from xml_generator.types import XmlParser
parser = XmlParser()
with open(
file="xml_generator/tests/samples/complex.xml", mode="r", encoding="utf-8"
) as f:
original_xml = f.read()
parser.feed(original_xml)
root = parser.close()
xml_string = root.to_xml(
declaration=True, declaration_tag='<?xml version="1.0" encoding="UTF-8"?>\n'
)
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xml-generator-seobaeksol-0.5.0.tar.gz.
File metadata
- Download URL: xml-generator-seobaeksol-0.5.0.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad980d6b758548518cc528870985aedad4287b7ee4247065040f3c1ac24adc21
|
|
| MD5 |
66b4f86c9ca1a5695cdf3e123f29441f
|
|
| BLAKE2b-256 |
e6271318e0ccd9bdf211ccc46f8370e7fe1f6a331790b4eb10ebade1a981c72a
|
File details
Details for the file xml_generator_seobaeksol-0.5.0-py3-none-any.whl.
File metadata
- Download URL: xml_generator_seobaeksol-0.5.0-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1755ce8e6489697c79d4c0126f2096ccbe47378e098e0857e78babea304968af
|
|
| MD5 |
daca27940f4e251d7eb2a43bd29d1630
|
|
| BLAKE2b-256 |
4a35d142a63a830afb1f72ccdd193f84e0d7d01a0a7ac7be6612349336b54abe
|