答案 0 :(得分:0)
试试这个:
import xml.etree.ElementTree as ET
import xml.dom.minidom
parent_file_path = 'samplexml.xml'
parent_tree = ET.parse(parent_file_path)
parent = parent_tree.getroot()
xmlstr = xml.dom.minidom.parseString(ET.tostring(parent)).toprettyxml()
print xmlstr