Posted by kohsuke
on February 10, 2006 at 7:23 PM PST
JAXP 1.3 comes with a nice XML validation API (I was involved in designing this API.) Today I'm going to explain how to use this API to validate your XML documents with RELAX NG.
RELAX NG is a schema language for XML. It allows you to describe a structure of XML in a way much easier to read/write than W3C XML Schema, and it can be useful both for humans (to understand what XML is OK) and for programs (to mechanically determine if an XML is OK or not.)
Historically many good RELAX NG validators, like MSV or Jing , has been available through another validation API called JARV , which predates JAXP 1.3.
But since now JAXP 1.3 is available widely (in particular it's in J2SE 5.0), it would be really nice if one can use them through JAXP 1.3 validation API. So I wrote a little adapter layer so that I can use validators written for JARV through JAXP 1.3.
To use this, you don't have to know anything about JARV. Just put isorelax-jaxp-bridge.jar and a JARV implementation in your classpath, and write a program like this:
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.RELAXNG_NS_URI);
The complete example is also available. For more about JAXP 1.3 validation API, see this .