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
The easiest solution I think is switching to the lxml library. In most circumstances you can just change your import from import xml.etree.ElementTree as etree to from lxml import etree or similar.
You can then use the pretty_print option when serializing:
tree.write(filename, pretty_print=True)
(also available on etree.tostring)