Python: convert JSON to XML
Question: Are you aware of any good Python `JSON <-> XML` parser that could do the
following:

Use the following JSON:

    
    
    var json = {
        "root_element_name" : {
            "attr1" : "value",
            "attr2" : "value",
            "elements": {
                "element_name1" : "value",
                "element_name2" : "value"
            }
        }
    }
    

and convert to the following XML & vice versa:

    
    
    <root_element_name attr1="value" attr2="value" >
         <option name="element_name1" value="value"/>
         <option name="element_name2" value="value"/>
    </root_element_name>
    

Any suggestions much appreciated.


Answer: Python a allows you to convert from JSON into a native dict (using json or, in
versions < 2.6, simplejson)

You can do this with the help of a library
<https://github.com/quandyfactory/dict2xml>

Or you can do this by loading it into `json.loads`.For the more explaiantion
of this method please have a look
[here](http://stackoverflow.com/questions/1019895/serialize-python-dictionary-
to-xml)

A sample for converting to xml

    
    
      >>> import xmltools
    
    >>> d = {'a':1, 'b':2.2, 'c':'three' }
    >>> xx = xmltools.WriteToXMLString(d)
    >>> print xx
    

The result

    
    
    <?xml version="1.0" encoding="UTF-8"?>
    <top>
      <a>1</a>
      <b>2.2</b>
      <c>three</c>
    </top>
    

