Ignoring incorrect XML encoding declarations

"Martin v. Löwis" martin at v.loewis.de
Wed Jan 15 20:27:47 EST 2003


Peter Scott wrote:
> The parser wisely spots this error and throws a SAXParseException, and I 
> can't parse the file. I've tried just catching the exception and 
> printing an error, then keeping on parsing, but it didn't work. Is there 
> any way I can get the SAX parser to ignore the 'encoding="UTF-16"' and 
> parse the file with the real encoding?

If you invoke xml.parsers.expat.ParserCreate with an encoding argument, 
expat should use this one instead of the declared encoding. This feature 
  is not exposed through SAX, though.

Regards,
Martin






More information about the Python-list mailing list