Pretty printing XML in Python

后端 未结 26 2302
一个人的身影
一个人的身影 2020-11-22 02:18

What is the best way (or are the various ways) to pretty print XML in Python?

26条回答
  •  独厮守ぢ
    2020-11-22 03:11

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

提交回复
热议问题