On Tue, 2004-03-02 at 05:32, [EMAIL PROTECTED] wrote:
> Hi,
>
> I load an XML file with Apache digester and I have a strange behaviour
> with XML schema validation. I have enabled XML schema validation and
> provided a XML input file with a syntax error in it => The syntax error is
> well detected by Apache Digester:
> ########################################################################
> 2554 [main] ERROR org.apache.commons.digester.Digester - Parse Error at
> line 5 column 36: cvc-enumeration-valid: Value 'GLOBA' is not facet-valid
> with respect to enumeration '[GLOBAL, PERL5]'.
> org.xml.sax.SAXParseException: cvc-enumeration-valid: Value 'GLOBA' is not
> facet-valid with respect to enumeration '[GLOBAL, PERL5]'
> at
> org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown
> Source)
> at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
> ########################################################################
>
> But no exception SAXParseException is raised as I thought it would be. I
> was expecting to catch a SAXParseException and actually it doesn't happen.
> The stack trace seems to confirm to a SAXParseException should be raised
> but it not the case.
> try {
[snip]
> digester.parse(xmlfile);
>
> }
>
> catch (SAXParseException saxex) {
> logger.error(
> "Sax parsing error processing file " +
> xmlfile.getName());
> throw new LogInputSourceException("Error during xml input
> source processing");
> }
Hi,
>From a quick glance at the code, it looks like Digester registers itself
as an org.xml.sax.ErrorHandler (it extends
org.xml.sax.helpers.DefaultHandler), and that by default it ignores all
sax errors:
public void error(SAXParseException exception) throws SAXException {
log.error("Parse Error at line " + exception.getLineNumber() +
" column " + exception.getColumnNumber() + ": " +
exception.getMessage(), exception);
if (errorHandler != null) {
errorHandler.error(exception);
}
}
Craig/Robert: why does Digester ignore sax errors by default?
ldewavrin: you can provide an ErrorHandler which Digester will delegate
to. So I suggest you write a subclass of org.xml.sax.ErrorHandler which
always rethrows the input exception and register it with the Digester
using:
digester.setErrorHandler(errorHandler).
Hopefully this will resolve your issue...
Regards,
Simon
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]