In my xml file I have <?xml version="1.0" encoding="utf-8"?>
at the beginning. But it disappears if I encode it to a string. By that I mean my string does not have it anymore at the beginning. I thought I can simply insert it in my string like in the code below (which worked when printing it), but when I wanted to save the string as a xml again on my laptop and open it, <?xml version="1.0" encoding="utf-8"?>
wasn't there anymore.
import xml.etree.ElementTree as ET
tree = ET.parse(r'someData.xml')
root = tree.getroot()
xml_str = ET.tostring(root, encoding='unicode')
xml_str = '<?xml version="1.0" encoding="utf-8"?>' + xml_str
Does anybody know how to encode the xml to a string without loosing <?xml version="1.0" encoding="utf-8"?>
OR how to save the string as xml without loosing it? My aim is to have it in my exported xml. Thank you in advance!!