You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xmlbeans.apache.org by pe...@vero.co.nz on 2007/09/03 04:50:11 UTC

Error handler overwritten on parse

I'm looking to parse and validate incoming XML in a single pass with 
customised error handling for validation errors.

Here's what I do:

Get a new instance of a validating reader.
Turn on the validation features.
Set its error handler with a new instance of my customer error handler.
Create a new instance of XML options and set its XML reader to be my 
validating one with the custom error handler.
Parse the XML using the XML options.

Prior to the parse my error handler is an instance of 
nz.co.vero.renew.datatransfer.component.messagegateway.GatewayManagerImpl$1 
but after the call it is an 
org.apache.xmlbeans.impl.store.Locale$XmlReaderSaxLoader and so my custom 
error handling code never gets called :-(

This looks like a bug to me - it should check the error handler isn't null 
before reassigning it, or at the very least state in the docs that the 
parse method mutates the XML options underlying XML reader by overwriting 
its error handler reference. Am I missing something? Some other properties 
I should have set? A different (efficient) way of doing it?

Thanks in advance for any help / thoughts, Pete


PS: Java 1.4.2, XML4J 4.3.6,  XMLBeans 2.3.0

PPS: Code snippet:

XMLReader reader = XMLReaderFactory.createXMLReader();
reader.setFeature("http://apache.org/xml/features/validation/schema", 
true);
reader.setFeature("http://xml.org/sax/features/validation", true);
reader.setErrorHandler(new ErrorHandler() { // Snip custom handling
        public void error(SAXParseException e) {}
        public void fatalError(SAXParseException e) {}
        public void warning(SAXParseException e) {}
});
XmlOptions options = new 
XmlOptions().setUnsynchronized().setLoadUseXMLReader(reader);
log.config("Error handler: " + 
reader.getErrorHandler().getClass().getName());
RatePolicyRequestDocument.Factory.parse(request.getCharacterStream(), 
options);
log.config("Error handler: " + 
reader.getErrorHandler().getClass().getName());

Pete van de Water
Technical Consultant
Vero Insurance New Zealand Limited
Mobile +64 21 226 6228
Facsimile +64 9 363 2586
Email peter_van_de_water@vero.co.nz
www.vero.co.nz 

**********************************************************************
CAUTION - This message is intended for the addressee named above. It
may contain privileged or confidential information. If you are not the
intended recipient of this message you must not use, copy, distribute
or disclose it to anyone.
**********************************************************************