xmlstr=ET.tostring(xroot, encoding="utf-8") DOM = minidom.parseString(xmlstr) if sys.version_info >= (3, 0): dbout("") dbout(xmlstr) dbout("") pxml=DOM.toprettyxml(indent="", newl="\n", encoding="utf-8").decode("utf-8") dbout("") dbout(pxml) dbout("") print(pxml)