Hi Hiranya, Interestingly, I have found an easy way to validate a Schema document. We just need to use the JAXP validation API (which will be visible to the user normally).
Below is a code snippet for this: SchemaFactory sf = SchemaFactory.newInstance .. sf.setErrorHandler .. Schema s = sf.newSchema(new StreamSource(schemapath)); The 'newSchema' call would not succeed if XML Schema has an error. The XSModel or the Grammar technique you wrote, is a low level API which is normally used within Xerces. On Fri, Jun 12, 2009 at 11:49 AM, Mukul Gandhi<gandhi.mu...@gmail.com> 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: j-dev-unsubscr...@xerces.apache.org For additional commands, e-mail: j-dev-h...@xerces.apache.org