is there a similar library to simplejson, which would enable quick serialization of data to and from XML.
e.g. json.loads('{vol:'III', title:'Magical Unicorn'}')
e.g. json.dumps([1,2,3,4,5])
Any ideas?
You're not going to find anything for xml as consistent as json, because xml doesn't know about data types. It depends on you to follow conventions or enforce adherence to an xml schema file.
That being said, if you're willing to accept the XML-RPC data structure mapping and a few limitations, check out the xmlrpclib package that lives in the Python standard library:
http://docs.python.org/library/xmlrpclib.html#convenience-functions
>>> import xmlrpclib
>>> s = xmlrpclib.dumps( ({'vol':'III', 'title':'Magical Unicorn'},))
>>> print s
<params>
<param>
<value><struct>
<member>
<name>vol</name>
<value><string>III</string></value>
</member>
<member>
<name>title</name>
<value><string>Magical Unicorn</string></value>
</member>
</struct></value>
</param>
</params>
>>> xmlrpclib.loads(s)[0]
({'vol': 'III', 'title': 'Magical Unicorn'},)
>>>
You can look how they have done it in Django: xml_serializer.py and tailor this to your needs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With