Project

Profile

Help

SaxonC ErrorHandler

Added by Paul Greve over 1 year ago

Using SaxonC 12.2.

SaxonJ provides the capability to set an ErrorHandler callback (on the SchemaFactory, ValidatorHandler and XMLReader). This provides the ability to distinguish between warnings, errors and fatal errors when parsing and validating source documents.

Does that same capability exist in SaxonC? I have been unable to find it.

Parse/validation error messages are reported via the SaxonApiException. However, the SaxonApiException does not include an "error level" (warning vs error vs fatal error).

Is there a way to get the "error level" for parse/validation errors in SaxonC?


Replies (2)

RE: SaxonC ErrorHandler - Added by Michael Kay over 1 year ago

Unfortunately the ErrorHandler design in JAXP that you refer to is deeply flawed, because when it comes to schema validation, it really doesn't say what conditions should be classified as warnings, errors, and fatal errors. So although SaxonJ supports the JAXP API for the sake of compatibility, it's a very unsatisfactory design and we made efforts to improve it in our own s9api API design.

In particular we introduced the concept of a validation report, in XML format, containing full details of all invalidities detected during schema validation. We use the term "invalidity" to indicate a divergence of the source document from the schema: whether you treat this as a warning, an error, a fatal error, or simply as a neutral data point is entirely up to you.

One of the unfortunate aspects of the JAXP ErrorHandler is that it communicates information in terms of Java Exception objects. Java Exceptions are very expensive because they hold stack trace information that's completely irrelevant for this kind of use case. Invalidity should not be treated as exceptional, it should be treated as normal expected feedback from the validation process.

RE: SaxonC ErrorHandler - Added by Paul Greve over 1 year ago

Thanks for the clarification. I agree with you that invalidity should not be considered exceptional. I see the SchemaValidator::getValidityReport() function. I'll check it out.

    (1-2/2)

    Please register to reply