Skip to main content

pyxml2dict

pyxml2dict is an open source python library, which used for converting xml to python dict

pyxml2dict is licensed under the GPL-3.0

Prefix the attribute in the dictionary @attribute , the value corresponding to key is #text

Installing

Install with pip:


    $pip install pyxml2dict

Usage


  from pyxml2dict import XML2Dict

  if __name__ == '__main__':
      xml_str1 = """<root id="1"><items><item>1</item><item>2</item></items></root>"""
      xml_str2 = """<root id="1"><age>20</age><items><item id="0">1</item><item>2</item></items></root>"""
      xml2dict = XML2Dict()
      print xml2dict.fromstring(xml_str1)
      print xml2dict.fromstring(xml_str2)
      #if you want namespace to be removed then:
      xml_str3 = """<root id="1" xmlns="somenamespace"><items><item>1</item><item>2</item></items></root>"""
      print xml2dict.fromstring(xml_str3)
      print xml2dict.fromstring(xml_str3, remove_namespace=True)

print result


 {'root': {'items': {'item': ['1', '2']}, '@id': '1'}}

 {'root': {'items': {'item': [{'#text': '1', '@id': '0'}, '2']}, 'age': '20', '@id': '1'}}

 {'{somenamespace}root': {'@id': '1', '{somenamespace}items': {'{somenamespace}item': ['1', '2']}}}

 {'root': {'items': {'item': ['1', '2']}, '@id': '1'}}

Thanks

In XML2Dict , _parse_node algorithm comes from https://github.com/undefine1995/xml2dict, It's very useful. Thanks for undefine1994.

Release files for pyxml2dict 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyxml2dict 1.0.3
File Size Uploaded
pyxml2dict-1.0.3.tar.gz 2.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyxml2dict 1.0.3
File Interpreter ABI Platform
pyxml2dict-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 17.7 kB

Release files / pyxml2dict-1.0.3.tar.gz

Download URL pyxml2dict-1.0.3.tar.gz
Size 2.7 kB
Tags Source
SHA-256 checksum
How to use checksums
e63bd843e81bd7c2bcf6e5f964af9362839cceb82ad298508bdfeca82c581376
BLAKE2b-256 checksum
How to use checksums
fa970ca63ebe3de229bb87e0b167d511002abe449eb16badcbb3ba045ade6733
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.2

Release files / pyxml2dict-1.0.3-py3-none-any.whl

Download URL pyxml2dict-1.0.3-py3-none-any.whl
Size 15.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1862525ebde900b6c6c699213dbc3c7d171d08744f0e73a7c91a6ae1b4670c31
BLAKE2b-256 checksum
How to use checksums
960dbd87278cf6fb2f406e62bd092fbdeca5e5b8c2399cb218d6f274868f1de0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.2

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files

1.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page