I am using python to do some conditional changes to an XML document. The incoming document has <?xml version="1.0" ?> at the top.
I'm using xml.etree.ElementTree.
How I'm parsing the changed XMl:
filter_update_body = ET.tostring(root, encoding="utf8", method="xml")
The output has this at the top:
<?xml version='1.0' encoding='utf8'?>
The client wants the "encoding" tag removed but if I remove it then it either doesn't include the line at all or it puts in encoding= 'us-ascii'
Can this be done so the output matches: <?xml version="1.0" ?>?
(I don't know why it matters honestly but that's what I was told needed to happen)
outxml = outxml.replace("encoding='utf8'", "", 1)filter_update_body = ET.tostring(root, encoding="utf8", method="xml") filter_update_body = filter_update_body.replace("encoding='utf8'", "", 1)and I got an error: "TypeError: a bytes-like object is required, not 'str'"replaceis a perfectly valid method of strings. Are you perhaps trying to write the file in binary mode?replacewithblike thisreplace(b"encoding='utf-8'", b"", 1)bin there do?