Validate an XML File Against Multiple Schema Definitions

So just in case anybody else runs into the same issue here, I needed to load a parent schema (and implicit child schemas) from a unit test – as a resource – to validate an XML String. I used the Xerces XMLSchemFactory to do this along with the Java 6 validator.

In order to load the child schema’s correctly via an include I had to write a custom resource resolver. Code can be found here:

To use the resolver specify it on the schema factory:

xmlSchemaFactory.setResourceResolver(new ResourceResolver());

and it will use it to resolve your resources via the classpath (in my case from src/main/resources). Any comments are welcome on this…

Leave a Comment