Hi Hiranya, On Fri, Jun 12, 2009 at 10:45 AM, Hiranya Jayathilaka<[email protected]> wrote: > 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?
I think, you can use either of the approaches. The XSModel approach I mentioned also validates imported schemas as well. Infact, the 'loadURI' method I mentioned, builds XSModel from the Grammar object (it does something like, ((XSGrammar) fSchemaLoader.loadGrammar(new XMLInputSource(null, uri, null))).toXSModel(). -- Regards, Mukul Gandhi --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
