Hi Folks, By going through the Xerces samples I came up with the following code to validate an XML schema document.
XMLGrammarPreparser preparser = new XMLGrammarPreparser(); preparser.registerPreparser(XMLGrammarDescription.XML_SCHEMA, null); preparser.setFeature("http://xml.org/sax/features/namespaces", true); preparser.setFeature("http://xml.org/sax/features/validation", true); preparser.setFeature(" http://apache.org/xml/features/validation/schema", true); preparser.setErrorHandler(new MyErrorHandler()); Grammar g = preparser.preparseGrammar(XMLGrammarDescription.XML_SCHEMA, new XMLInputSource(null, xsdUrl, null)); This seems to be working really well. It even validates any imported schemas etc. All the errors are reported to the registered error handler. WDYT about this approach over the XSModel construction approach? Thanks, Hiranya On Thu, Jun 11, 2009 at 6:47 PM, Mukul Gandhi <gandhi.mu...@gmail.com>wrote: > Hi Michael, > I saw the code in XSLoaderImpl.java where it's written like (in the > 'loadURI' method): > > catch (Exception e){ > fSchemaLoader.reportDOMFatalError(e); > return null; > } > > The definition of reportDOMFatalError is something like below: > > void reportDOMFatalError(Exception e) { > if (fErrorHandler != null) { > DOMErrorImpl error = new DOMErrorImpl(); > error.fException = e; > error.fMessage = e.getMessage(); > error.fSeverity = DOMError.SEVERITY_FATAL_ERROR; > fErrorHandler.getErrorHandler().handleError(error); > } > } > > Looking at the method reportDOMFatalError, I thought some default > error handler has been registered with the XMLSchemaLoader. > > But your suggestion looks great, to register a custom error handler. I > would explore it further and would get back with questions to the > list.. > > On Thu, Jun 11, 2009 at 6:25 PM, Michael > Glavassevich<mrgla...@ca.ibm.com> wrote: > > I didn't see that in the snippet you posted. If you want programatic > access > > to error information then you need to explicitly register an error > handler: > > > > DOMErrorHandler myErrorHandler = ...; > > > > XSImplementation xsImpl = (XSImplementation) > > registry.getDOMImplementation("XS-Loader"); > > XSLoader xsLoader = xsImpl.createXSLoader(null); > > > > DOMConfiguration config = xsLoader.getConfig(); > > config.setParameter("error-handler", myErrorHandler); // <-- set the > error > > handler > > > > -- > Regards, > Mukul Gandhi > > --------------------------------------------------------------------- > To unsubscribe, e-mail: j-dev-unsubscr...@xerces.apache.org > For additional commands, e-mail: j-dev-h...@xerces.apache.org > > -- Hiranya Jayathilaka Software Engineer; WSO2 Inc.; http://wso2.org E-mail: hira...@wso2.com; Mobile: +94 77 633 3491 Blog: http://techfeast-hiranya.blogspot.com