Loading ...
Sorry, an error occurred while loading the content.

Validating in Java using JAXP

Expand Messages
  • Avi Flax
    Hi, I m trying to validate documents using RELAX NG schemata, and JAXP, but I m having trouble. In order to isolate my issues, I ve created a test case. I have
    Message 1 of 3 , Oct 9, 2009
    • 0 Attachment
      Hi, I'm trying to validate documents using RELAX NG schemata, and
      JAXP, but I'm having trouble.

      In order to isolate my issues, I've created a test case.

      I have a single directory which contains the following files:

      wadl.xml
      wadl.rnc
      RngValidate.java
      run
      jing.jar
      RngValidate.class
      isorelax.jar
      isorelax-jaxp-bridge-1.0.jar

      I believe I've obtained the latest versions of jing.jar, isorelax.jar,
      and isorelax-jaxp-bridge-1.0.jar.

      The source of my RngValidate class is:

      --BEGIN SOURCE-----------------------------------

      import javax.xml.validation.SchemaFactory;
      import javax.xml.validation.Schema;
      import javax.xml.transform.stream.StreamSource;
      import javax.xml.XMLConstants;
      import java.io.File;

      /**
      * Sample main class for a test drive
      *
      * @author Kohsuke Kawaguchi (kk@...)
      * @author Avi Flax (avif@...)
      */
      public class RngValidate {
      public static void main(String[] args) throws Exception {
      SchemaFactory sf =
      SchemaFactory.newInstance(XMLConstants.RELAXNG_NS_URI);

      System.out.println("SchemaFactory is " + sf.getClass().getName());

      Schema s = sf.newSchema(new File(args[0]));

      System.out.println("Schema is " + s.getClass().getName());

      s.newValidator().validate(new StreamSource(args[1]));
      }
      }

      --END SOURCE-----------------------------------

      As you can see, this is just a slightly modified version of
      org.iso_relax.verifier.jaxp.validation.Main.

      I then try to run this class with the following command:

      java "-Djavax.xml.validation.SchemaFactory:http://relaxng.org/ns/structure/1.0=org.iso_relax.verifier.jaxp.validation.RELAXNGSchemaFactoryImpl"
      -Djaxp.debug=true -cp
      .:isorelax.jar:isorelax-jaxp-bridge-1.0.jar:jing.jar RngValidate
      wadl.rnc wadl.xml



      The output of the command is:


      JAXP: using thread context class loader
      (sun.misc.Launcher$AppClassLoader@2c2bbd86) for search
      JAXP: Looking up system property
      'javax.xml.validation.SchemaFactory:http://relaxng.org/ns/structure/1.0'
      JAXP: The value is
      'org.iso_relax.verifier.jaxp.validation.RELAXNGSchemaFactoryImpl'
      JAXP: createInstance(org.iso_relax.verifier.jaxp.validation.RELAXNGSchemaFactoryImpl)
      JAXP: loaded org.iso_relax.verifier.jaxp.validation.RELAXNGSchemaFactoryImpl
      from jar:file:/Users/avi/Dev/Experiments/rng-jaxp-test/isorelax-jaxp-bridge-1.0.jar!/org/iso_relax/verifier/jaxp/validation/RELAXNGSchemaFactoryImpl.class
      JAXP: failed to look up system property
      'javax.xml.validation.SchemaFactory:http://relaxng.org/ns/structure/1.0'
      org.iso_relax.verifier.VerifierConfigurationException: no validation
      engine available for: http://relaxng.org/ns/structure/1.0
      at org.iso_relax.verifier.VerifierFactory.newInstance(VerifierFactory.java:333)
      at org.iso_relax.verifier.VerifierFactory.newInstance(VerifierFactory.java:337)
      at org.iso_relax.verifier.jaxp.validation.SchemaFactoryImpl.<init>(SchemaFactoryImpl.java:35)
      at org.iso_relax.verifier.jaxp.validation.RELAXNGSchemaFactoryImpl.<init>(RELAXNGSchemaFactoryImpl.java:12)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
      at java.lang.Class.newInstance0(Class.java:355)
      at java.lang.Class.newInstance(Class.java:308)
      at javax.xml.validation.SchemaFactoryFinder.createInstance(SchemaFactoryFinder.java:314)
      at javax.xml.validation.SchemaFactoryFinder._newFactory(SchemaFactoryFinder.java:172)
      at javax.xml.validation.SchemaFactoryFinder.newFactory(SchemaFactoryFinder.java:145)
      at javax.xml.validation.SchemaFactory.newInstance(SchemaFactory.java:205)
      at RngValidate.main(RngValidate.java:15)
      JAXP: found null in $java.home/jaxp.properties
      JAXP: looking into
      jar:file:/Users/avi/Dev/Experiments/rng-jaxp-test/isorelax-jaxp-bridge-1.0.jar!/META-INF/services/javax.xml.validation.SchemaFactory
      JAXP: Reading jar:file:/Users/avi/Dev/Experiments/rng-jaxp-test/isorelax-jaxp-bridge-1.0.jar!/META-INF/services/javax.xml.validation.SchemaFactory
      java.lang.ClassNotFoundException:
      http\://relaxng.org/ns/structure/1.0=org.iso_relax.verifier.jaxp.validation.RELAXNGSchemaFactoryImpl
      at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:319)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:330)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:254)
      at javax.xml.validation.SchemaFactoryFinder.createClass(SchemaFactoryFinder.java:278)
      at javax.xml.validation.SchemaFactoryFinder.loadFromService(SchemaFactoryFinder.java:424)
      at javax.xml.validation.SchemaFactoryFinder._newFactory(SchemaFactoryFinder.java:246)
      at javax.xml.validation.SchemaFactoryFinder.newFactory(SchemaFactoryFinder.java:145)
      at javax.xml.validation.SchemaFactory.newInstance(SchemaFactory.java:205)
      at RngValidate.main(RngValidate.java:15)
      JAXP: all things were tried, but none was found. bailing out.
      JAXP: unable to find a factory for http://relaxng.org/ns/structure/1.0
      Exception in thread "main" java.lang.IllegalArgumentException: No
      SchemaFactory that implements the schema language specified by:
      http://relaxng.org/ns/structure/1.0 could be loaded
      at javax.xml.validation.SchemaFactory.newInstance(SchemaFactory.java:207)
      at RngValidate.main(RngValidate.java:15)


      I'm running this on Mac OS X 10.5.8 with Java 1.6.0_15, 64-bit.

      I figure I'm missing something, but of course I'm not sure what.

      I'd really appreciate some help in trying to get this to work!

      I'd definitely be open to using a different set of libraries, I just
      happen to be starting with Jing. If someone wants to recommend MSV, or
      some other validator, that'd be great. I'd particularly like to know
      if there's a validator somewhere which supports JAXP directly, without
      a bridge. I did try MSV but didn't get very far.

      Thanks!

      Avi

      --
      Avi Flax » Partner » Arc90 » http://arc90.com
    • MURATA Makoto (FAMILY Given)
      ... Isn t msv.jara missing? In my environment (Windows XP), if I omit this jar frile, I have the same error as you reported. Cheers, Makoto
      Message 2 of 3 , Nov 6, 2009
      • 0 Attachment
        > java "-Djavax.xml.validation.SchemaFactory:http://relaxng.org/ns/structure/1.0=
        >org.iso_relax.verifier.jaxp.validation.RELAXNGSchemaFactoryImpl"
        >-Djaxp.debug=true -cp
        >".;isorelax.jar;isorelax-jaxp-bridge-1.0.jar;jing.jar" RngValidate
        >wadl.rnc wadl.xml

        Isn't msv.jara missing? In my environment (Windows XP), if I omit this
        jar frile, I have the same error as you reported.

        Cheers,
        Makoto
      • Avi Flax
        On Fri, Nov 6, 2009 at 17:45, MURATA Makoto (FAMILY Given)
        Message 3 of 3 , Nov 8, 2009
        • 0 Attachment
          On Fri, Nov 6, 2009 at 17:45, MURATA Makoto (FAMILY Given) <EB2M-MRT@...> wrote:
           
          Isn't msv.jara missing?  In my environment (Windows XP), if I omit this
          jar frile, I have the same error as you reported.

          Thanks Makoto.

          In this case, I was trying to use Jing, not MSV.

          I don't recall at the moment, but there was a specific reason I wanted to try Jing before MSV.

          I think after that, I did try MSV, and I think I had similar problems.

          However, it sounds like you've had success with MSV, so perhaps I'll try that again.

          Thanks,
          Avi
        Your message has been successfully submitted and would be delivered to recipients shortly.