How do I get Python’s ElementTree to pretty print to an XML file?

xml.etree.ElementTree.indent(tree, space=" ", level=0) Appends
whitespace to the subtree to indent the tree visually. This can be
used to generate pretty-printed XML output. tree can be an Element or
ElementTree. space is the whitespace string that will be inserted for
each indentation level, two space characters by default. For indenting
partial subtrees inside of an already indented tree, pass the initial
indentation level as level.

Serialize Python dictionary to XML

There is simple JSON serialization module with name “simplejson” which easily serializes Python objects to JSON. I’m looking for similar module which can serialize to XML. Answers: Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as … Read more