A simple Python XML to Dictionary parser
Project description
xml_to_dict
A simple Python XML to Dictionary parser.
The package is based on this answer from Stack Overflow. It parses entities as well as attributes following this XML-to-JSON "specification".
I just added the from_nest function, which lets you retrieve a value from the nested dictionaries.
Install
pip3 install xml_to_dict --user
Usage
from xml_to_dict import XMLtoDict
sample_xml = (
'<response>'
'<results>'
'<user>'
'<name>Ezequiel</name>'
'<age>33</age>'
'<city>San Isidro</city>'
'</user>'
'<user>'
'<name>Belén</name>'
'<age>30</age>'
'<city>San Isidro</city>'
'</user>'
'</results>'
'</response>'
)
parser = XMLtoDict()
print(parser.parse(sample_xml)) # {'response': {'results': {'user': [{'name': 'Ezequiel', 'age': '33', 'city': 'San Isidro'}, {'name': 'Belén', 'age': '30', 'city': 'San Isidro'}]}}}
print(parser.value_from_nest('.*ser', sample_xml)) # [{'name': 'Ezequiel', 'age': '33', 'city': 'San Isidro'}, {'name': 'Belén', 'age': '30', 'city': 'San Isidro'}]
Contributing
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch
- Commit your Changes
- Push to the Branch
- Open a Pull Request
License
Distributed under the MIT License. See LICENSE
for more information.
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
xml_to_dict-0.1.6.tar.gz
(2.7 kB
view hashes)
Built Distribution
Close
Hashes for xml_to_dict-0.1.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f312372bba121a72a204d40ed2dd91f4027f5ea14e236befcc6c0e5aed4044f |
|
MD5 | 83248062daff587adbb6f84010a6e2c1 |
|
BLAKE2b-256 | 3d0e0ed3711e4007d56ab432bfb956af9076213eae4ac6bd9c81ff3ea8e50f65 |