# pyxml2dict
**Repository Path**: ai0376/pyxml2dict
## Basic Information
- **Project Name**: pyxml2dict
- **Description**: convert xml file to python dict
- **Primary Language**: Python
- **License**: GPL-3.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2018-06-05
- **Last Updated**: 2020-12-18
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
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 = """- 1
- 2
"""
xml_str2 = """20- 1
- 2
"""
xml2dict = XML2Dict()
print xml2dict.fromstring(xml_str1)
print xml2dict.fromstring(xml_str2)
#if you want namespace to be removed then:
xml_str3 = """- 1
- 2
"""
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.