The following code demonstrates how to pretty print an XML file in Python using the minidom library.
main.py370 chars16 linesThe function prettify_xml takes a file path as an argument, reads the XML file at that path, formats it with indentation and line breaks using toprettyxml(), and writes the formatted XML back to the same file.
You can call the function like this:
main.py42 chars2 lines
gistlibby LogSnag