Handling errors in PyXML/SAX

Martin von Loewis loewis at informatik.hu-berlin.de
Fri Jul 20 03:31:09 EDT 2001


Tom Bridgman <bridgman at wyeth.gsfc.nasa.gov> writes:

> I'm finally starting to work with the SAX parser and DTDs.  With the SAX
> defalult error handler, when parsing a file, I get error messages like:
> 
> ERROR in Unknown:94:22: Element 'animationtype' not declared
> ERROR in Unknown:98:18: Element 'thumbnail' not declared
> ERROR in Unknown:99:14: Element 'medialist' not declared
> 
> which I find ideal but for the fact that I would like to print the file
> name rather than 'Unknown'.
> 
> I've tried setting the systemID (which seems to be where the 'Unknown'
> comes from) in a locator object like so:
> 
> location=xmlreader.Locator()
> location.setSystemId=inputfilename
> self.handler.setDocumentLocator(location)
> 
> but still get 'Unknown'.

Setting the locator on the content handler won't tell the parser
anything; instead, the parser is supposed to invoke setDocumentLocator
itself.

What you need to do is to pass a proper InputSource to .parse(),
instead of passing, say, an open file.

Regards,
Martin




More information about the Python-list mailing list