Skip to main content

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

Metadata

Release files for xml-generator-seobaeksol 0.4.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xml-generator-seobaeksol 0.4.6
File Size Uploaded Provenance Actions
xml-generator-seobaeksol-0.4.6.tar.gz 6.2 kB Without provenance Details for xml-generator-seobaeksol-0.4.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for xml-generator-seobaeksol 0.4.6
File Interpreter ABI Platform Actions
xml_generator_seobaeksol-0.4.6-py3-none-any.whl Python 3 none any Details for xml_generator_seobaeksol-0.4.6-py3-none-any.whl

Total release size: 13.0 kB

Release files / xml-generator-seobaeksol-0.4.6.tar.gz

Download URL xml-generator-seobaeksol-0.4.6.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
dde306f058d8f5faf1d9007314602dec17263bff2379d4b27d25fed405ac98e6
BLAKE2b-256 checksum
How to use checksums
8dfa4a88591fc6ecc0527d8819ac20db4b2101e1985167f1d44cebd0e4ea7804
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release files / xml_generator_seobaeksol-0.4.6-py3-none-any.whl

Download URL xml_generator_seobaeksol-0.4.6-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
369a658d4fc5fb2cadf17c0c5cb351d0f09347794ff0c5277fe82583f52a27c7
BLAKE2b-256 checksum
How to use checksums
2c2b5be1ba819b86cab7b177bf3f446e8aa57a1a1ed4080e119b7ba162f6774e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Security for xml-generator-seobaeksol 0.4.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page