I am using python to deal with xml file, I need to insert one line to the xml file, and the code is like this:
xobj = ET.parse('/src/xxx.xml')
xroot = xobj.getroot()
filename = ET.Element("filename")
filename.text = xmlname
xroot.insert(0, filename)
tree = ET.ElementTree(xroot)
tree.write('/dst/xxx.xml')
It did insert one line of contents to the original xml file, but it was not a line. My xml file becomes:
<filename>004228.xml</filename><object>
....
</object>
There should be a \n
between </filename>
and <object>
, but this method does not have that line spliter, how could I make the format look nice ?