Entry
Is there a python script similar to shelve or pickle that will take an array and convert it to XML code?
Sep 2nd, 2000 02:34
unknown unknown, Michal Wallace
Problem:
We have several arrays, some are multidimensional arrays, created with
NumPy. We'd like store these arrays in an XML data structure. Is there
a python script similar to shelve or pickle that will take an array and
convert it to XML code? Thanks.
Solution:
The xmlrpc module has routines to convert structures to XML (it's on
www.pythonware.com)
.. But if you want more control over what the XML looks like, you
could always start with something like:
def xmlify(somearray):
res = "<cell>"
for item in somearray:
if type(item)==type([]):
res = res + xmlify(item)
else:
res = res + item
res = res + "</cell>"
return res
print '<?xml version="1.0"?>'
print xmlify(yourMultiDimensionalArray)