xml to dictionary tool for python
Project description
xmlpydict 📑
Requirements
python 3.7+
Installation
To install xmlpydict, using pip:
pip install xmlpydict
Quickstart
>>> from xmlpydict import parse
>>> parse("<package><xmlpydict language='python'/></package>")
{'package': {'xmlpydict': {'@language': 'python'}}}
>>> parse("<person name='Matthew'>Hello!</person>")
{'person': {'@name': 'Matthew', '#text': 'Hello!'}}
Goals
Create a consistent parsing strategy between xml and python dictionaries. xmlpydict takes a more laid pack approack to enforcing the syntax of xml.
Features
xmlpydict allows for multiple root elements. The root object is treated as the python object.
xmlpydict supports the following
CDataSection: CDATA Sections are stored as {'#text': CData}.
Comments: Comments are tokenized for corectness, but have no effect in what is returned.
Element Tags: Allows for duplicate attributes, however only the latest defined will be taken.
Characters: Similar to CDATA text is stored as {'#text': Char} , however this text is stripped.
dict.get(key[, default]) will not cause exceptions
# Empty tags are containers
>>> from xmlpydict import parse
>>> parse("<a></a>")
{'a': {}}
>>> parse("<a/>")
{'a': {}}
>>> parse("<a/>").get('href')
None
>>> parse("")
{}
Attribute prefixing
# Change prefix from default "@" with keyword argument attr_prefix
>>> from xmlpydict import parse
>>> parse('<p width="10" height="5"></p>', attr_prefix="$")
{"p": {"$width": "10", "$height": "5"}}
Exceptions
# Grammar and structure of the xml_content is checked while parsing
>>> from xmlpydict import parse
>>> parse("<a></ a>")
Exception: not well formed (violation at pos=5)
Unsupported
Prolog / Enforcing Document Type Definition and Element Type Declarations
Entity Referencing
Namespaces
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
Built Distribution
File details
Details for the file xmlpydict-0.0.8.tar.gz
.
File metadata
- Download URL: xmlpydict-0.0.8.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b81c7ec34d8228dec362d62966103edd3b83b496eda79f2cce386a45a3324332 |
|
MD5 | 0be3938aba6ca3269b29a520433f1756 |
|
BLAKE2b-256 | e3e434dd4530ddc5ba2820da0385da31da75f69ff634fe33a96d3ee5661512f1 |
File details
Details for the file xmlpydict-0.0.8-cp310-cp310-manylinux_2_34_x86_64.whl
.
File metadata
- Download URL: xmlpydict-0.0.8-cp310-cp310-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 149.1 kB
- Tags: CPython 3.10, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80b940da99a263a18ec1b382696995d90330de635492fc0dfd4d15a8228f40bc |
|
MD5 | 4091665fc5b54d362de07cc813eb73b1 |
|
BLAKE2b-256 | e211d7fb92ddcceba6a153f44c03e61ec24fd43e4f66dd79dedb5f994647baa9 |