How to validate XML against XSD 1.1 in Java?
Unfortunately, neither the JDK bundled version (as of Java 8) nor the latest official version from maven central (2.11.0) contains XSD 1.1 implementation.
You actually need the 2.11.0-xml-schema-1.1-beta
version of Xerces to able to run the example in the FAQ you have linked.
You may do one of the following.
Download the
Xerces2 Java 2.11.0 (XML Schema 1.1) (Beta)
binaries from Xerces website and manually add jars to the classpath (or install locally via Maven). Link: http://xerces.apache.org/mirrors.cgi. You need at least the following:cupv10k-runtime.jarorg.eclipse.wst.xml.xpath2.processor_1.1.0.jarxercesImpl.jarxml-apis.jar
Use the following unofficial maven dependency.
<dependency> <groupId>org.opengis.cite.xerces</groupId> <artifactId>xercesImpl-xsd11</artifactId> <version>2.12-beta-r1667115</version></dependency>
I don't think you can use the JAXP service mechanism to search for an XSD 1.1 processor. Load Saxon or Xerces in the normal way, and then enable XSD 1.1 processing. For Saxon this is done using
SchemaFactory.setProperty("http://saxon.sf.net/feature/xsd-version", "1.1")
UPDATE 2021-09-04 In recent Saxon releases, XSD 1.1 is the default, and no special property needs to be set to enable it.
There is a generic XML validator that works with XML Schema v1.1, which uses xercesImpl-xsd11
2.12-beta-r1667115
. The validator is available here as a Maven plugin, and here as an embeddable library.