An open-source library that is used for converting XML to a python dictionary.
This library:
- can work with namespace
- can transform XML value into python object (integer, boolean, datetime & custom transformers) using the "type" attribute
Installation:
pip install xmltodict3
or
pip install git+https://github.com/dart-neitro/xmltodict3
Example 1 (Simple case):
>>> from xmltodict3 import XmlTextToDict
>>> text = """
... <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
... <xs:root attr="attr_value">
... data
... </xs:root>
... </xs:schema>
... """
>>> result = XmlTextToDict(text, ignore_namespace=True).get_dict()
>>> print(result)
{'schema': {'root': {'@attr': 'attr_value', '#text': 'data'}}}
Example 2 (with transformers):
>>> from xmltodict3 import XmlTextToDict
>>> import xmltodict3.transformers as transformers
>>> text = """
... <root>
... <values>
... <int_value type="integer">
... 123
... </int_value>
... </values>
... </root>
... """
>>> transformer_list = transformers.DefaultTransformerList
>>> pull_transformers = transformers.PullTransformers(*transformer_list)
>>> pull_transformers.set_removing_types(True)
>>> xml_to_dict = XmlTextToDict(text)
>>> xml_to_dict.use_pull_transformers(pull_transformers)
>>> result = xml_to_dict.get_dict()
>>> print(result)
{'root': {'values': {'int_value': 123}}}
More examples
Metadata
Release files for xmltodict3 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| xmltodict3-0.0.4.tar.gz | 5.6 kB | Without provenance | Details for xmltodict3-0.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| xmltodict3-0.0.4-py3-none-any.whl | Python 3 | none | any | Details for xmltodict3-0.0.4-py3-none-any.whl |
Total release size: 12.2 kB
Release files / xmltodict3-0.0.4.tar.gz
| Download URL | xmltodict3-0.0.4.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f0a6abe07ea6e39aea8465573c82e3fa2ea0ffbe4ad56d0d600185a412d932ab
|
|
BLAKE2b-256 checksum How to use checksums |
6b31b1c886938e4c78325643b1710ea895cebc38208da84bd16f8028669e4cf4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
|
Release files / xmltodict3-0.0.4-py3-none-any.whl
| Download URL | xmltodict3-0.0.4-py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f328da8ef9785a7a594dac6c47b5b597f98114edb601cf7d44852a37b99ac856
|
|
BLAKE2b-256 checksum How to use checksums |
4f5cf7f5b371a6ee0e6ec1b0727e8d91b32b38fbdf876d3da3833ece72d5c107
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
|
Security for xmltodict3 0.0.4
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.