I have a XML file encoded in UTF-8 with some bad content that brokes my script when I try to parse it with:
from xml.etree import ElementTree as etree
etree.parse(file).getroot()
I've seen some old answers where they use "recover=True" in the parser but after reading etree's docs it seems it's not allowed anymore. Also I can't manually replace the characters because I'm afraid this could happen again in the future with other characters, so I'm looking for a solution that completely removes any single non-allowed character. Is there any built-in function or way of doing this?
recover
option is available in lxml, but not in ElementTree. See lxml.de/api/lxml.etree.XMLParser-class.html.