1

I need to validate XML files against XSD 1.1 schema. My question is: Does the Xerces library supports now XSD 1.1?

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

When i include this in my pom then it doesnot work . It gives following Error :

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

But when i add the following jars manually in classpath then it kinda works:

cupv10k-runtime.jar
org.eclipse.wst.xml.xpath2.processor_1.1.0.jar
xercesImpl.jar
xml-apis.jar

My Code :

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

Do we need to add the jars manually for this to work. Isn't the library avialable in maven? Plese help if anyone has any idea.

NAVOZ
  • 45
  • 7
  • Xerces-J 2.12.0 and later supports XSD 1.1 https://xerces.apache.org/mirrors.cgi – Yitzhak Khabinsky Jul 15 '22 at 14:18
  • Yes, but the link you have added is the binary package. I have downloaded the jars from there and added. But the maven dependency does not works? – NAVOZ Jul 15 '22 at 14:25
  • Maybe you can check here: https://xerces.apache.org/xerces2-j/ – Yitzhak Khabinsky Jul 15 '22 at 14:27
  • 1
    I think I am not clear with my question. I know Xerces 2.12.2J works with XML 1.1 but when added manually. How can i use it in my project? Because when i am using the maven dependency then it is not working. Manually adding the jars is wel working. – NAVOZ Jul 15 '22 at 14:38

2 Answers2

0

The blog article https://blog.adamretter.org.uk/xerces-xsd11-maven/ describes the dilemma and explains that the author set up https://search.maven.org/artifact/org.exist-db.thirdparty.xerces/xercesImpl/2.12.2/jar and that that way you can use e.g.

<dependency>
    <groupId>org.exist-db.thirdparty.xerces</groupId>
    <artifactId>xercesImpl</artifactId>
    <version>2.12.2</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>
Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
  • Thanks @Martin . That means there is no official way of doing it? Because these dependencies are unofficial right? – NAVOZ Jul 18 '22 at 07:14
  • @NAVOZ, if you want to call it that way, right, I don't know who officially works on Apache Xerces and whether some of them is supposed to provide an official Maven entry but Adam Retter and the eXist guys simply stepped in to fill the gap, I think, for their own projects but of course to give others the opportunity to use that. – Martin Honnen Jul 18 '22 at 09:32
  • Thanks Martin for the answer. These dependencies works but we chose to manually add the jars in maven and then using the dependency in our projects. – NAVOZ Jul 21 '22 at 08:00
0

I tried both suggestions, and both worked for me only when the XML was invalid. However, when it was valid I was getting tons of Exceptions regarding missing com.ibm.icu, so in order to make it work for me, I added the following dependency:

<dependency>
   <groupId>com.ibm.icu</groupId>
   <artifactId>icu4j</artifactId>
   <version>72.1</version>
</dependency>

I hope this helps someone.

Regards!