To pretty print XML in Python, you can use the minidom
module which is part of the standard library.
Here is an example code snippet to pretty print XML in Python using minidom
:
main.py368 chars14 lines
In this example, we define an XML string, parse it using minidom
, and then pretty print the resulting data using the toprettyxml()
method of the dom
object. Finally, we print the pretty XML string.
This should produce a nicely formatted XML string that is easier to read and understand.
gistlibby LogSnag