I have created a xml file using xml.etree.ElementTree in python. I then use
tree.write(filename, "UTF-8")
to write out the documen
There is no pretty printing support in ElementTree, but you can utilize other XML modules.
For example, xml.dom.minidom.Node.toprettyxml():
Node.toprettyxml([indent=""[, newl=""[, encoding=""]]])Return a pretty-printed version of the document. indent specifies the indentation string and defaults to a tabulator; newl specifies the string emitted at the end of each line and defaults to \n.
Use indent and newl to fit your requirements.
An example, using the default formatting characters:
>>> from xml.dom import minidom
>>> from xml.etree import ElementTree
>>> tree1=ElementTree.XML('1 2 ')
>>> ElementTree.tostring(tree1)
'1 2 '
>>> print minidom.parseString(ElementTree.tostring(tree1)).toprettyxml()
1
2
>>>