Skip to main content

xml to dictionary tool for python

Project description

xmlpydict 📑

XML Tests PyPI versions PyPI

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-back approach to enforce the syntax of XML. However, still ensures fast speeds by using finite automata.

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

xmlpydict-0.0.9.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

xmlpydict-0.0.9-cp310-cp310-manylinux_2_34_x86_64.whl (149.8 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.34+ x86-64

File details

Details for the file xmlpydict-0.0.9.tar.gz.

File metadata

  • Download URL: xmlpydict-0.0.9.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for xmlpydict-0.0.9.tar.gz
Algorithm Hash digest
SHA256 39b6a7edd6d8d281c85d0aaf6f7df3d1206d5116566218212d8baf9eb1c28dd1
MD5 fa16fcd3059b03ca7f0b63ec1ba5ec68
BLAKE2b-256 8b141561edaa5cdb0cda9bab749dd8cdbffc8428800ed13fbde03ae2082eca89

See more details on using hashes here.

File details

Details for the file xmlpydict-0.0.9-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for xmlpydict-0.0.9-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 8966d4f10c8ad974b0987ba0e75d4f6f93d18aad0bf7dbcf3546ce07cb7614e3
MD5 54da2fd4e786d476cc8bad6bceda41aa
BLAKE2b-256 2ddbeaf91be429d1a9ab576e7c89f5297c139dca8d8281fae49fd580d8c98030

See more details on using hashes here.

Supported by

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