ironpython2
ironpython2 copied to clipboard
pyexpat does not support Python encoding names
pyexpat does not support Python encoding names. This is because the names are not understood by System.Xml.XmlReader which is used under the hood.
from xml.etree import ElementTree as ET
text = ET.fromstring(b"<?xml version='1.0' encoding='iso8859'?><a></a>")
A possible solution for this would be to peek at the start of the XML file to get the encoding, do the decoding ourselves and then use a StringReader. Another option would be to peek at the start, and replace the encoding with an alias that XmlReader understands.
I think your example needs to use ET.fromstring