Handling errors in PyXML/SAX

Tom Bridgman bridgman at wyeth.gsfc.nasa.gov
Fri Jul 20 22:18:52 CEST 2001


Martin,

YES!  

parser.parse(inputfilename) does work.  It's not clear from the
documentation at http://py-howto.sourceforge.net/xml-ref/node20.html
that systemID is a file name, even though I was guessing this at a
couple of spots.

Thanks,
Tom

Martin von Loewis wrote:
> 
> 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

--
Dr. William T."Tom" Bridgman           Scientific Visualization Studio
Global Science & Technology, Inc.      NASA/Goddard Space Flight Center
Email: bridgman at wyeth.gsfc.nasa.gov    Code 935
Phone: 301-286-1346                    Greenbelt, MD 20771
FAX:   TBD                             http://svs.gsfc.nasa.gov/



More information about the Python-list mailing list