I would like to validate XML documents using RELAX NG schemata, and I would like to use the JAXP validation API.
From Googling around, it appeared that I could use J
See Stefan Bodewig's Weblog written on March 7, 2008 titled RELAX NG Validation in XMLUnit:
Since last night XMLUnit's trunk contains a new Validator class that is based on javax.xml.validation which is part of JAXP 1.3 (i.e. Java5+).
...
To the best of my knowledge there is no JAXP implementation that supported RELAX NG out of the box. Sun's own JAXP 1.4 (Java6+) certainly doesn't. Some searching around brought me to Kohsuke Kawaguchi's Blog who should know, given his work on JAXP, Sun's Multi Schema Validator, isorelax and other stuff.
Using his isorelax-bridge and Jing didn't get me anywhere on Java6. I went back to Kohsuke Kawaguchi's article and read the comments: the bridge doesn't work with Java6 since they changed the SchemaFactory lookup algorithm. OK, tried Java5 instead - progress, I now get a NullPointerException somewhere inside of Jing, so at least it is loading the factory. Next I replaced Jing with MSV (which is here now, no matter how many links out there lead you to the WebServices stack page at Sun, so much for "good URLs never change") and really, my simplistic tests pass.
So you may have to jump through some hoops to get RELAX NG support into your JAXP setup - in my case Java5, MSV and Kawaguchi's bridge worked, but the comments indicate it should be doable with Java6 as well - but once you manage to configure everything correctly, XMLUnit will now be there to let you assert your document's validity in Unit tests. It seems that it doesn't work for compact syntax, though.
To read the comments on Kohsuke Kawaguchi's blog, you have to use archive.org because somehow they are all gone now:
Java 5 interprets the Service Provider file as a list of key/value pairs, which is a violation to the Java 5 & 6 JAR file specification but happens to match your example.
Java 6 parses the Service Provider file as specified, ie. as a list of fully qualified class names, but thus fails to instantiate your adapter's SchemaFactory as the Service Provider file's contents are invalid.
To be compatible with both Java 5 and Java 6 without having to change the JAXP-JARV-adapter JAR file, one can simply add another JAR file containing a correct javax.xml.validation.SchemaFactory Service Provider file.