Howto create this XML string?

Fredrik Lundh fredrik at
Fri Jan 20 15:23:22 CET 2006

Sbaush wrote:

> Is possible to have the XML in a string (for example xmlstring) and for
> printing do a print xmlstring ?

most about anything that can be written to a file can be written to a string
using the StringIO module:

    file = StringIO.StringIO()
    data = file.getvalue()

for elementtree, you can also use the tostring function:

    data = ET.tostring(elem)


More information about the Python-list mailing list