Ant integration with XML schemas

This should cover W3C XML Schema, Relax NG and DTD related problems.
tsm21
Posts: 25

Ant integration with XML schemas

Thu Jun 25, 2015 9:54 am

Hello,

we have developed an rng file with embedded rules of Relaxng and schematron.

But we want to integrate both the schemas(relaxng and schematron) in to single ant build file.

We have already found a jar file (JING.jar) which integrates relaxNG rules with ant environment and (ant-schematron.jar) file which validates only schematron rules.,
but we want a build or jar file which validates both the schema rules of an XML file simultaneously.

We neither couldn't find such kind of jar file or couldn't integrate both the schemas in to a single build file.

Is there a way to validate an xml file with embedded schema rules(Relaxng and schematron) through ant build file.




Thank you
Regards
Sai
Radu
Posts: 5226

Re: Ant integration with XML schemas

Thu Jun 25, 2015 11:02 am

Hi Sai,

When you validate an XML with a Relax NG with embedded Schematron rules, you actually need to perform two separate validations. So you would probably need to do something like:

1) Validate the XML with the Relax NG schema using Jing.
2) Extract from the Relax NG schema the Schematron rules to an external temporary Schematron file by applying an XSLT stylesheet over the RNG schema. You can find such a stylesheet here:

OXYGEN_INSTALL_DIR\frameworks\schematron\impl\RNG2Schtrn.xsl

3) Use that temporary created Schematron file to validate the XML document.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
tsm21
Posts: 25

Re: Ant integration with XML schemas

Mon Jun 29, 2015 8:08 am

Hi Radu,

Thanks for the solution.

We have a doubt if we could run the xml schema(relaxNG + schematron) validations through command line arguments instead of oXygen XML editor GUI.





Thank you
Sai
tsm21
Posts: 25

Re: Ant integration with XML schemas

Tue Jun 30, 2015 10:17 am

According to this solution given by Radu
Hi Sai,

When you validate an XML with a Relax NG with embedded Schematron rules, you actually need to perform two separate validations. So you would probably need to do something like:

1) Validate the XML with the Relax NG schema using Jing.
2) Extract from the Relax NG schema the Schematron rules to an external temporary Schematron file by applying an XSLT stylesheet over the RNG schema. You can find such a stylesheet here:

OXYGEN_INSTALL_DIR\frameworks\schematron\impl\RNG2Schtrn.xsl

3) Use that temporary created Schematron file to validate the XML document.

Regards,
Radu


We have used the RNG2Schtrn.xsl to generate a schematron file.

but when we ran the ant build file after adding ant-schematron.jar file to the environment, we got the following error

build.xml

Code: Select all

<taskdef name="schematron"
         classname="com.schematron.ant.SchematronTask"
         classpath="lib\ant-schematron.jar" />
   
     <target name="validate" description="Test with a Fileset">
      <schematron schema="sch/sample.sch" failonerror="false">
         <fileset dir="xml" includes="*.xml" />
      </schematron>
     </target>


error:
java.lang.NoClassDefFoundError: net/sf/saxon/TransformerFactoryImpl


saxonhe.jar and ant-schematron.jar are added to the respective local ant environment path, but still we are getting this error.

could you please help us to resolve this issue.





Thank you
Sai
Radu
Posts: 5226

Re: Ant integration with XML schemas

Tue Jun 30, 2015 10:40 am

Hi Sai,

Your taskdef seems to refer a single JAR library. Maybe it should also refer to the Saxon 9 libraries.
I'm not sure if you are running the task with fork="true" or not. Because if you fork it, it will definitely not use the JAR libraries from the parent ANT process.

So maybe you should give all the necessary libraries to the task:

Code: Select all

<path id="libraries">
  <fileset dir="lib/saxon/">
    <include name="*.jar"/>
  </fileset>
  <fileset dir="lib">
    <include name="*.jar"/>
  </fileset>
</path>
<taskdef name="schematron"
         classname="com.schematron.ant.SchematronTask"
         classpathref="libraries" />
...............


Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
tsm21
Posts: 25

Re: Ant integration with XML schemas

Wed Jul 01, 2015 9:32 am

Hi Radu,

Thanks for the solution.

Is it possible to run the xml schema(relaxNG + schematron) validation files through command line arguments instead of oXygen XML editor GUI?





Thank you
Sai
Radu
Posts: 5226

Re: Ant integration with XML schemas

Wed Jul 01, 2015 9:59 am

Hi Sai,

If you mean that you want to call from the command line the "Validate" action which is done inside Oxygen, then no.
If you want to run an ANT script (the script you are building) from the command line, of course, this is possible.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Return to “XML Schemas”

Who is online

Users browsing this forum: No registered users and 1 guest