Does the XML library look like simplejson / json? - Python

Is there a similar library for simplejson that allows you to quickly serialize 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?

+5
source share
5 answers

You will not find anything for xml as serial as json, because xml does not know about data types. It is up to you to follow conventions or enforce the xml schema file.

If you want to accept the XML-RPC structure mapping and a few limitations, check out the xmlrpclib package, which is 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'},)
>>> 
+3
source

, Django: xml_serializer.py .

+3

. xmlrpc ... , , : - ElementTree - , XML-.

, , , , , , ? json, pickle -, ?

xmlrpclib:

xmlrpclib.dumps(data)

xmlrpclib, . , : 2 ^ 31-1, . "" , . , .

, xmlrpc . , , . XML .

+2

xml, json, " " xml python. Heck XML- , XSL.

API, ,

For a good XML parsing tutorial using the Element Tree, I refer you to Mark Pilgrim Dive in Python3

+2
source

What about lxml ?

+1
source

All Articles