I create a root:
from xml.etree.ElementTree import Element, tostring
root = Element("root")
Then generating a string repr of XML:
xmlstr = tostring(root, encoding="utf8", method="xml")
And create my xml file:
myFile = open(file, "w")
myFile.write(xmlstr)
myFile.close()
After all operations my file looks like that:
<?xml version="1.0" encoding="UTF-8"?>
<root>
</root>
What I should do to add some comments after xml declaration? Tried to use xml.etree.ElementTree.Comment but not sure how to do it properly. My desirable file should looks:
<?xml version="1.0" encoding="UTF-8"?>
<!-- My comments -->
<root>
</root>
Feel free to ask if you don't understand something. Thanks!
getprevious(). See stackoverflow.com/q/69652602/407651 and stackoverflow.com/q/23025245/407651addprevious()!