How to serialize an xml document in Python
Irmen de Jong
irmen at -NOSPAM-REMOVETHIS-xs4all.nl
Wed Mar 19 15:17:13 EST 2003
Antun Karlovac wrote:
> So far I've been printing it out to the console:
>
> xml.dom.ext.PrettyPrint( doc )
>
> But now I want to assign the serialized string of the XML to a
> variable.
>
> How do I do that?
>>> help(xml.dom.ext.PrettyPrint)
Help on function PrettyPrint in module xml.dom.ext:
PrettyPrint(root, stream=<open file '<stdout>', mode 'w'>, encoding='UTF-8',
indent=' ', preserveElements=None)
..... this means you can do something like this:
>>> import cStringIO as StringIO
>>> s=StringIO.StringIO()
>>> xml.dom.ext.PrettyPrint(doc,stream=s)
>>> print s.getvalue()
---Irmen de Jong.
More information about the Python-list
mailing list