Write element tree to a file as XML.
Arguments:
*file_or_filename* -- file name or a file object opened for
writing
*encoding* -- the output encoding (default: US-ASCII)
*xml_declaration* -- bool indicating if an XML declaration should
be added to the output. If None, an XML
declaration is added if encoding IS NOT
either of: US-ASCII, UTF-8, or Unicode
*default_namespace* -- sets the default XML namespace (for
"xmlns")
*method* -- either "xml" (default), "html, "text", or "c14n"
*short_empty_elements* -- controls the formatting of elements
that contain no content. If True
(default) they are emitted as a single
self-closed tag, otherwise they are
emitted as a pair of start/end tags
>>> for country in root.findall('country'):
... # using root.findall() to avoid removal during traversal
... rank = int(country.find('rank').text)
... if rank > 50:
... root.remove(country)
...
>>> tree.write('output.xml')