javaxmlvalidationxsdxerces2-j

Xerces v2.12.0 XML Schema 1.1 Validation


Xerces 2.12.0 claims to support XSD 1.1 (https://xerces.apache.org/xerces2-j/faq-xs.html), but I can't get past the SchemaFactory.newInstance call.

More context:

This line fails:

import javax.xml.validation.SchemaFactory;
//...
schemaFactory = SchemaFactory.newInstance("http://www.w3.org/XML/XMLSchema/v1.1");

With the exception:

java.lang.IllegalArgumentException: No SchemaFactory that implements the schema language specified by: http://www.w3.org/XML/XMLSchema/v1.1 could be loaded

Here's the maven dependency I'm using:

<dependency>
    <groupId>xerces</groupId>
    <artifactId>xercesImpl</artifactId>
    <version>2.12.0</version>
</dependency>

While I've found several posts claiming this works, it doesn't for me.

I've seen folks recommending this very old dependency:

<dependency>
    <groupId>org.opengis.cite.xerces</groupId>
    <artifactId>xercesImpl-xsd11</artifactId>
    <version>2.12-beta-r1667115</version>
</dependency>

And yeah, that kinda works, but I'd prefer using the Apache version, especially since it claims to support XSD 1.1.


Solution

  • Xerces-J 2.12.0 has two distributions: one (Xerces-J-bin.2.12.0-xml-schema-1.1.zip) that contains XML Schema 1.1 support and one (Xerces-J-bin.2.12.0.zip) that does not. Your Maven dependency seems to be pointing to the Xerces 12.2.0 jar without XML Schema 1.1 support. As of today, I don't think the XML Schema 1.1 version got published to Maven.

    The Apache community has been helping with making Xerces available in Maven repos. You may want to bump the discussion here: https://issues.apache.org/jira/browse/XERCESJ-1695.