Copyimport xml.dom.minidom
dom = xml.dom.minidom.parse(xml_fname) # or xml.dom.minidom.parseString(xml_string)
pretty_xml_as_string = dom.toprettyxml()
Answer from Ben Noland on Stack OverflowCopyimport xml.dom.minidom
dom = xml.dom.minidom.parse(xml_fname) # or xml.dom.minidom.parseString(xml_string)
pretty_xml_as_string = dom.toprettyxml()
lxml is recent, updated, and includes a pretty print function
Copyimport lxml.etree as etree
x = etree.parse("filename")
print etree.tostring(x, pretty_print=True)
Check out the lxml tutorial: https://lxml.de/tutorial.html
PyCharm: how to pretty-print XML elements in the debugger
Proper indentation or perry print using ElementTree(XML)
Someone please help me. I've been stuck on this assingment for whole day now :( Why my program only adds the last value from list into my XML file? The output is right but for some reason my program only adds 1 value to the list. I loop over the list which contains every item and therefore my program should add every item from that list into the XML file
My code,output and desired output:https://pastebin.com/pWiWi2MW
More on reddit.comLXML: Adding line break for readability
Document Management Systems?
Videos
» pip install xmlformatter
I just met PyCharm, and I really like it. But the first thing I am using it for is to manipulate XML files, and I'd like the debugger to show the XML elements I'm building in an easily read format. I am using etree from the lxml module. The result of
print(headerElement, pretty_print=True)
is
b'<HEADER>\n <MESSAGE_NUMBER>0</MESSAGE_NUMBER>\n <SIMULATION_INDEX>N</SIMULATION_INDEX>\n</HEADER>\n'
I need the debugger to show me this:
<HEADER> <MESSAGE_NUMBER>0</MESSAGE_NUMBER> <SIMULATION_INDEX>N</SIMULATION_INDEX> </HEADER>
I am using Win7 Pro.
Thank you very much.