import xml.dom.minidom
dom = xml.dom.minidom.parse(xml_fname)
# or
# dom = xml.dom.minidom.parseString(xml_string)
pretty_xml_as_string = dom.toprettyxml()
A blog about coding
import xml.dom.minidom
dom = xml.dom.minidom.parse(xml_fname)
# or
# dom = xml.dom.minidom.parseString(xml_string)
pretty_xml_as_string = dom.toprettyxml()