Hi Thomas,
If you want to stop parsing using SAX, you must throw an exception. From the SAX documentation:
- "WARNING: If an application does not register an ErrorHandler, XML parsing errors will go unreported, except that SAXParseExceptions will be thrown for fatal errors. In order to detect validity errors, an ErrorHandler that does something with error() calls must be registered."
"For XML processing errors, a SAX driver must use this interface in preference to throwing an exception: it is up to the application to decide whether to throw an exception for different types of errors and warnings. Note, however, that there is no requirement that the parser continue to report additional errors after a call to fatalError. In other words, a SAX driver class may throw an exception after reporting any fatalError. Also parsers may throw appropriate exceptions for non-XML errors. For example, XMLReader.parse() would throw an IOException for errors accessing entities or the document."
If you don't throw an exception, Xalan will never know that an error occurred, so an error code will not be returned. If you want to collect all of the error messages, then report them, you'll be responsible for determining if processing was successful or not. As long as you're doing separate compilation of the stylesheet, and parsing of the source document, that's OK.
However, if your error handler doesn't do the right thing, the results are undefined if you try to transform with a stylesheet that with a fatal error. The same can be said for the parsed source tree.
Dave
![Inactive hide details for [EMAIL PROTECTED]](gifSEGSsUQmcB.gif)
![]() | ![]()
12/03/2002 02:36 PM | ![]() To: xalan-c-users@xml.apache.org cc: (bcc: David N Bertoni/Cambridge/IBM) Subject: RE: Xalan 1.3/1.4 behvior change when compiling a stylesheet |
So it is an absolute (or recommended) behavior for the error handler to
throw an exception to stop the parse?
I was hoping that we could let the parse continue (not throwing an exception
in the error handler) in order to collect all the error messages and just
use a flag to say if any errors occur or not that we check after the parsing
to see if it was ok or not. May be I should direct such question to the
Xerces mailing list.
Thomas
-----Original Message-----
From: David N Bertoni/Cambridge/IBM [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, December 03, 2002 4:52 PM
To: xalan-c-users@xml.apache.org
Subject: RE: Xalan 1.3/1.4 behvior change when compiling a stylesheet
Hi Thomas,
This sounds like a change in the parser, or a bug fix that exposes incorrect
behavior on the part of your ErrorHandler derivative. I suspect what's
happening is the parser is recovering from the error and continuing. The
appropriate behavior is for your ErrorHandler to throw some sort of
exception to stop the parse.
Dave
[EMAIL PROTECTED]
oftware.com To:
xalan-c-users@xml.apache.org
cc: (bcc: David
N Bertoni/Cambridge/IBM)
12/03/2002 11:15 AM Subject: RE: Xalan
1.3/1.4 behvior change when compiling a stylesheet
Thanks for the information.
Actually, we are not throwing an exception from the error handler and this
is probably the issue. In 1.3 it seems that we did not have to
(compileStylesheet was still returning the appropriate success/failure
code), but that was may be already a mistake. We are going to change the
code to throw an exception. If the problem is still not fixed, I will open a
bug report.
Thomas
-----Original Message-----
From: David N Bertoni/Cambridge/IBM [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, December 03, 2002 1:48 PM
To: xalan-c-users@xml.apache.org
Subject: Re: Xalan 1.3/1.4 behvior change when compiling a stylesheet
Hi Thomas,
That sounds like a bug. You are throwing an exception from your
ErrorHandler, right?
This could also be a change in how the parser is handling things. Are you
talking about well-formedness errors in the stylesheet, or perhaps XPath
errors in stylesheet elements?
If you could open a bug report, with a minimal input document and stylesheet
that reproduce the problem, that would be great.
Dave
[EMAIL PROTECTED]
oftware.com To:
xalan-c-users@xml.apache.org
cc: (bcc: David
N Bertoni/Cambridge/IBM)
12/03/2002 10:26 AM Subject: Xalan
1.3/1.4 behvior change when compiling a stylesheet
A quick question in case someone experienced the same problem. If I
configure a XalanTransformer with an error handler and if I compile a
stylesheet, any errors in the stylesheet are reported through the error
handler. In Xalan 1.3, the return of the compileStylesheet operation was
also different from 0 (success) in case any errors were reported through the
error handler. In Xalan 1.4, it seems that even if some errors are reported
through the error handler, the return of the compileStylesheet is set to 0
(success). Is it an expected behavior change or should I investigate a
little more to make sure that I am not doing anything wrong?
Thanks.
Thomas