How would I convert an XML element into string and a string back to XML format using xml.elementtree in web2py ?
2 Answers
Using the standard library, you'd use the StringIO writer and the parseString function:
>>> from StringIO import StringIO
>>> from xml.dom.minidom import parseString
>>> e = parseString('<foo/>')
>>> out = StringIO()
>>> e.writexml(out)
>>> s = out.getvalue()
>>> print(s)
<?xml version="1.0" ?><foo/>
>>> e2 = parseString(s)