[XML-SIG] Error handling in PyExpat

Radestock, Guenter guenter.radestock@sap.com
Wed, 21 Mar 2001 12:05:51 +0100


Hello,

I am using PyExpat to parse XML files and sometimes these files are not
correct.  If
I find an error in my handler (start_element, end_element or characters), I
raise
an exception and abort processing the XML file.  If I raise the exception my
self in
the handler, parser.ErrorLineNumber (and other variables describing the
error position) are not available to my code (ErrorLineNumber contains a
random
value); that is in the exception handler that catches my exception.

It should be possible to detect the exception in the expat parser module and
set
call set_error() in pyexpat.c if the information is available from expat.  I
could not
check the expat documentation right now (sourceforge is currently
unavailable and
I don't have it locally) but I hope, somebody has thought of this.
Unfortunately
the (C level) handlers are void functions so there must be another way to
tell expat
that processing has failed.

I have checked my (between PyXML-0.6.3 and 0.6.4) PyExpat source and the
xmlplus sources
for the SAX implementation but did not find the code I am looking for.  Are
there
plans to implement this or should I do it my self?  What I need is:

If I raise an exception inside a handler, pyexpat.c.set_error() should be
called
(or some other function that gets line number, column number, byte posision
etc.).
I am not sure if this should be done for every exception or only for
subclasses
of expat.error.

Thanks in advance for any help.

- Guenter