Xerces XML Schema 1.1 validation with Maven
Whilst working on migrating the eXist-db project from Ant to Maven, I had an issue whereby our tests for XML Schema 1.1 validation started failing. In my pom.xml
I had the following:
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.12.0</version>
</dependency>
<!-- xpath2 and java-cup are needed at runtime
for xercesImpl Schema 1.1 support -->
<dependency>
<groupId>org.exist-db.thirdparty.org.eclipse.wst.xml</groupId>
<artifactId>xpath2</artifactId>
<version>1.2.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>edu.princeton.cup</groupId>
<artifactId>java-cup</artifactId>
<version>10k</version>
<scope>runtime</scope>
</dependency>
When our Java code tried to acquire an XML Schema 1.1 validator we received the error message:
Exception in thread "main" java.lang.IllegalArgumentException: No SchemaFactory that implements the schema language specified by: http://www.w3.org/XML/XMLSchema/v1.1 could be loaded
at javax.xml.validation.SchemaFactory.newInstance(SchemaFactory.java:215)
at ...
We know that Apache Xerces officially introduced XML Schema 1.1 support in its release version 2.12.0... So what's the problem?
To cut a long story short, the problem is version naming! The Apache Xerces project released two variants of Xerces 2.12.0; The first variant (let's call this the "classic variant"), only supports XML Schema 1.0, the second variant builds on the classic variant and adds XML Schema 1.1 support. Unfortunately, they are both known as Xerces 2.12.0.
The "official" Maven artifacts for Xerces 2.12.0 on Maven Central appear to be the classic variant which does not include XML Schema 1.1 support.
We were unable to find a version of Xerces 2.12.0 with XML Schema 1.1 support that was available from Maven Central. Therefore, we decided to remedy this by publishing our own artifacts. In addition, to solve the variant problem with the official artifacts, we realised that we could use Maven's classifier support. By using classifiers we can differentiate between the 2.12.0 classic variant and the variant that supports XML Schema 1.1.
For everyones benefit, we have published our artifacts for Apache Xerces 2.12.0 to Maven Central under the groupId: org.exist-db.thirdparty.xerces
and artifactId: xercesImpl
. If you want the variant with XML Schema support, you can use the additional classifier: xml-schema-1.1
.
So, our updated pom.xml
file now looks like:
<dependency>
<groupId>org.exist-db.thirdparty.xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.12.0</version>
<classifier>xml-schema-1.1</classifier>
</dependency>
<!-- xpath2 and java-cup are needed at runtime
for xercesImpl Schema 1.1 support -->
<dependency>
<groupId>org.exist-db.thirdparty.org.eclipse.wst.xml</groupId>
<artifactId>xpath2</artifactId>
<version>1.2.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>edu.princeton.cup</groupId>
<artifactId>java-cup</artifactId>
<version>10k</version>
<scope>runtime</scope>
</dependency>
Happy Validating!