I am adding new elements (tags) to an existing XML file using python. The problem is that:
Appended XMl file is not printing each element on a new line (no whitespace); it is not pretty printed.
The output looks like this:
<queue flag="0x400004" node="parameter"><Enable Flag="0x400010" Id="167" node="parameter">true</Enable><Status Flag="0x200004" Id="168" node="parameter">Enabled</Status></queue><queue flag="0x400002" node="parameter"><Enable Flag="0x400010" Id="168" node="parameter">true</Enable><Status Flag="0x200004" Id="168" node="parameter">Enabled</Status></queue>
I want the output to be pretty printed so that each tag is on a separate line.
The python code I used for appending the xml file is:
import xml.dom.minidom as m
qu=dom.createElement("Queue") #creating elements to be appended
qu.setAttribute("node","parameter")
qu.setAttribute("Id","166")
qu.setAttribute("Flag","0x400004")
child=dom.createElement("Enable") #a sample child element "Enable" inside "queue"
child.setAttribute("node","object")
child.setAttribute("Id","167")
child.setAttribute("Flag","0x400010")
qu.appendChild(child) #child appended to "queue"
root.appendChild(qu) #appending "queue" to "root" tag of existing xml file
dom.writexml(open("existing_xml_file.xml","w")) #to append the existing xml file
What changes do I need to make to my code to get a pretty printed output?
Thank you in advance...!!!