Convert xml to dict and vice versa.
Python
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore Updating .gitignore. Nov 24, 2011
LICENSE First commit. Nov 24, 2011
README.md Update README.md Jan 27, 2014
fabfile.py Correcting method name s/clean/_clean Feb 14, 2012
setup.py Version bump for bug fix. Apr 10, 2013
tests.py Cleanups in test case Feb 10, 2014
xmldict.py Remove extra line Feb 10, 2014

README.md

xmldict

Convert xml to python dictionaries, and vice-versa.

Installation

pip install xmldict

On most of the systems, you will need the sudo permissions if you are doing a system wide install.

sudo pip install xmldict

Example

# Converting xml to dictionary
>>> xmldict.xml_to_dict('''
... <root>
...   <persons>
...     <person>
...       <name first="foo" last="bar" />
...     </person>
...     <person>
...       <name first="baz" last="bar" />
...     </person>
...   </persons>
... </root>
... ''')
{'root': {'persons': {'person': [{'name': {'last': 'bar', 'first': 'foo'}}, {'name': {'last': 'bar', 'first': 'baz'}}]}}}


# Converting dictionary to xml 
>>> xmldict.dict_to_xml({'root': {'persons': {'person': [{'name': {'last': 'bar', 'first': 'foo'}}, {'name': {'last': 'bar', 'first': 'baz'}}]}}})
'<root><persons><person><name><last>bar</last><first>foo</first></name></person><person><name><last>bar</last><first>baz</first></name></person></persons></root>'