May-25-2020, 02:48 PM
I am building an xml file using ElemetTree but I need to insert the encoding comment first.
Quote:<!--version="1.0" encoding="UTF-8"-->It seems like I have to create the root node first and then add the comment after. I need to figure out how to add the comment before the root node. Can someone tell me how to put the comment as the first line in the xml file using ElementTree? TIA.
ET.Comment(text='<!--version="1.0" encoding="UTF-8"-->') root=ET.Element('root')With this code the comment does not show up. If I add the comment using 'root.insert' after setting the root node, it show up as the 2nd line.