To serialize (convert to XML) the content of a document
contained in some ElementTree instance
, use this
method call:
ET
ET.write(file, pretty_print=False)
You must supply a writeable file object, or the name of a
file to be written. If you set argument pretty_print=True, the method will attempt to
fold long lines and indent the XML for legibility.
For example, if you have an ElementTree
instance in a variable page containing an
XHTML page, and you want to write it to the standard
output stream, this statement would do it:
import sys page.write(sys.stdout)