Python Glossary Русский

all Python 3xml.etree.ElementTreefunction

xml.etree.ElementTree.dump()

serialization

Prints an element or a tree to stdout as XML. Meant for debugging only.

Syntax

ET.dump(elem)

dump() returns nothing: x = ET.dump(e) gives None, and for a string you need tostring(e, encoding='unicode'). The docs call the output format implementation-dependent, so do not rely on it in tests or program output. It accepts both an Element and an ElementTree; since 3.8 it keeps attribute order.

Examples

import xml.etree.ElementTree as ET
e = ET.fromstring('<a x="1"><b/></a>')
ET.dump(e)  # → <a x="1"><b /></a>
print(ET.dump(e) is None)  # → <a x="1"><b /></a> / True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy