A useful Python module for a xml to dictionary converter

in «tip» by Michael Beard
Tags: , , , ,

make getting xml into a Python dict easy

I needed to compare 2 xml files to see where they differed and it's not so easy. I think that this module will help.

xmltodict

xmltodict is a Python module that makes working with XML feel like you are working with JSON, as in this "spec":

Here is an example from stackoverflow how to convert an xml string to a dictionary, answer by Martin Blech, writer of xmltodict.

xmltodict.parse("""
<?xml version="1.0" ?>
<person>
  <name>john</name>
  <age>20</age>
</person>""")
#### {u'person': {u'age': u'20', u'name': u'john'}}