Skip to main content

A simpler XML writer

Project description

XmlElement

A simpler XML writer.

Installation

pip install XmlElement

Test

>>> from XmlElement import XmlElement as X
>>> xml = X.from_string('<test><x/></test>')
>>> xml
XmlElement(test)

Usage

Creating XmlElements

from XmlElement import XmlElement as X

# Build a XML by nesting XmlElements:

xml = X('RootElement', s=[                             # root element without attributes
    X('Child1', {'testattr': 'Example attribute'}, [   # sub element with an attribute
        X('Child2', t='Example text value')            # sub-sub element with text value
    ])
])


# Alternative: Build a XML from a POJO-like object:

xml2 = X.from_object(
    node_name='RootElement',                           # root element without attributes
    data={                                             # no @-elements: root has -> no attributes
        'Child1': {                                    # sub element with an attribute @testattr
            '@testattr': 'Example attribute',
            'Child2': 'Example text value'             # sub-sub element with text value
        }
    }
)

print(str(xml) == str(xml2))                           # True

Accessing values by dot operator

print(xml)
print(xml.Child1[0].attributes['testattr']) # Example attribute
print(xml.Child1[0].Child2[0].text)         # Example text value

Accessing values dict-like (to avoid static type checker warnings)

print(xml)
print(xml['Child1'][0].attributes['testattr']) # Example attribute
print(xml['Child1'][0]['Child2'][0].text)      # Example text value

Project details


Download files

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

Source Distribution

XmlElement-0.2.0.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

XmlElement-0.2.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file XmlElement-0.2.0.tar.gz.

File metadata

  • Download URL: XmlElement-0.2.0.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.1

File hashes

Hashes for XmlElement-0.2.0.tar.gz
Algorithm Hash digest
SHA256 11cadee64a955326f366f67a24e0c7783542fbf9bde7c8565b1bbf82cd8f670d
MD5 18f52eb491ecf9539b3d4af8f7d81863
BLAKE2b-256 77530c5df32480ed290366c791e3ed1d4e59ef75e997b79020b923fc4424bf7b

See more details on using hashes here.

File details

Details for the file XmlElement-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: XmlElement-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.1

File hashes

Hashes for XmlElement-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a24220479a66689c11f94960ace0bd88f63ed8b95d7c2ac7d9dc75baa8542694
MD5 48d241a4ca188b7984819ecc07600bb1
BLAKE2b-256 92ead00553bcf5163f834e2ae3af14596e76e31c9b273b420fcc470facde68f8

See more details on using hashes here.

Supported by

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