Next / Previous / Contents / TCC Help System / NM Tech homepage

7.9. The tostring() function: Serialize as XML

To convert an Element and its content back to XML, use a function call of this form:

etree.tostring(elt, pretty_print=False, encoding=None)

where elt is an Element instance. The function returns a string containing the XML. For an example, see Section 7.8, “The SubElement() constructor”.

If you set the optional pretty_print argument to True, the method will attempt to insert line breaks to keep line lengths short where possible.

To output Unicode, use the keyword argument encoding=unicode.