I want to use xml.etree.ElementTree
to parse an XHTML document in Python 3. The document contains
entities, so I cannot use the default parser settings. I'd like to do something similar to:
with urllib.request.urlopen(BASE_URL) as url:
body = url.read()
parser = ET.XMLParser()
parser.parser.UseForeignDTD(True)
parser.entity.update(entitydefs)
etree = ET.ElementTree()
root = etree.fromstring(body)
But fromstring
is a free function in ElementTree
. How can I achieve something similar with ElementTree
instance?
parser.parser.UseForeignDTD(True)
doesn't work in Python 3. How come this answer was chosen as the correct answer? – Enthusiasm