An open-source library that is used for converting XML to a python dictionary.
Project description
An open-source library that is used for converting XML to a python dictionary.
This library:
- work with namespace
- can transform XML value into python object (integer, boolean, datetime & custom transformers) using the "type" attribute
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
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
xmltodict3-0.0.2.tar.gz
(5.3 kB
view hashes)
Built Distribution
Close
Hashes for xmltodict3-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2404bc6f26d701bf9b5bfb84952481fd6c218e3c126f410fb102a1a5c6142de3 |
|
MD5 | 071e74b3d6d33c2c848ef34eed9a5a9a |
|
BLAKE2b-256 | df914c678d217d6a7edb0379232f3422d81e0a2d2ac23cacfcbf49f657d058f8 |