Pretty printing XML in Python


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()


Leave a Reply

Your email address will not be published. Required fields are marked *