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

namespace error

Expand Messages
  • Amarendra Mishra
    All, I have already posted a question regarding this program. It does an in-memory dom validation using MSV (dom4j and Xerces as parser and jdk1.4). It works
    Message 1 of 2 , Aug 5, 2003
    • 0 Attachment
      All,

      I have already posted a question regarding this
      program.
      It does an in-memory dom validation using MSV (dom4j
      and Xerces as parser and jdk1.4). It works fine for
      schemas and instances with no namespaces.
      But if try to run it with schema and documents that
      has namespaces I'm getting exception. If I run the
      schema and the document with msv.jar from commmand
      line it says the document is valid.
      The exception I'm getting is:

      Loaded schema document:
      doc\wsUsage\latest11\new\WebServiceUsageRecords_v01_00.xsd
      [Error] WebServiceUsageRecords_v01_00.xsd:7:95:
      http://www.w3.org/TR/xml-schema-1#src-resolve?qw:UsageRecord&type
      definition
      Converted to DOM tree. First tag name is: UsageRecords
      Exception occurred: java.lang.NullPointerException
      java.lang.NullPointerException
      at
      org.apache.xerces.impl.xs.XMLSchemaLoader.resolveDocument(Unknown
      Source)
      at
      org.apache.xerces.impl.xs.XMLSchemaValidator.findSchemaGrammar(Unknown
      Source)
      at
      org.apache.xerces.impl.xs.XMLSchemaValidator.processAttributes(Unknown
      Source)
      at
      org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown
      Source)
      at
      org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown
      Source)
      at
      org.kohsuke.jarv.xerces.XercesVerifier.startElement(XercesVerifier.java:245)
      at
      org.iso_relax.verifier.impl.SAXEventGenerator.enter(Unknown
      Source)
      at
      jp.gr.xml.relax.dom.UDOMVisitor.traverse(Unknown
      Source)
      at
      jp.gr.xml.relax.dom.UDOMVisitor.traverseChildren(Unknown
      Source)
      at
      jp.gr.xml.relax.dom.UDOMVisitor.traverse(Unknown
      Source)
      at
      jp.gr.xml.relax.dom.UDOMVisitor.traverseChildren(Unknown
      Source)
      at
      jp.gr.xml.relax.dom.UDOMVisitor.traverse(Unknown
      Source)
      at
      jp.gr.xml.relax.dom.UDOMVisitor.traverseChildren(Unknown
      Source)
      at
      jp.gr.xml.relax.dom.UDOMVisitor.traverse(Unknown
      Source)
      at
      org.iso_relax.verifier.impl.SAXEventGenerator.makeEvent(Unknown
      Source)
      at
      org.iso_relax.verifier.impl.SAXEventGenerator.makeEvent(Unknown
      Source)
      at
      org.iso_relax.verifier.impl.VerifierImpl.verify(Unknown
      Source)
      at JARVTest.process(JARVTest.java:79)
      at JARVTest.start(JARVTest.java:38)
      at JARVTest.main(JARVTest.java:24)

      I'm also pasting the sample file.

      Thanx in advance.

      Best Rgds,
      Amarendra.

      ***************************************************


      import com.sun.msv.verifier.jarv.TheFactoryImpl;

      import javax.xml.parsers.SAXParserFactory;

      import org.dom4j.Document;
      import org.dom4j.DocumentException;
      import org.dom4j.io.SAXReader;
      import org.dom4j.io.SAXWriter;
      import org.dom4j.io.DOMWriter;

      //import org.w3c.dom.Document;
      import org.xml.sax.ErrorHandler;
      import org.xml.sax.SAXParseException;

      import org.iso_relax.verifier.Schema;
      import org.iso_relax.verifier.Verifier;
      import org.iso_relax.verifier.VerifierFactory;
      import org.iso_relax.verifier.VerifierHandler;

      public class JARVTest {

      public static void main(String[] args) {
      new JARVTest().start( args );
      }

      public void start(String[] args) {
      try {
      if ( args.length < 2 ) {
      System.out.println( "usage: <xmlDoc>
      <schemaDoc>" );
      return;
      }
      String xmlFile = args[0];
      String schema = args[1];

      SAXReader reader = new SAXReader();
      Document document = reader.read( xmlFile
      );
      process( document, schema );
      }
      catch (DocumentException e) {
      System.out.println( "Exception occurred: "
      + e );
      Throwable nestedException =
      e.getNestedException();
      if ( nestedException != null ) {
      System.out.println( "NestedException:
      " + nestedException );
      nestedException.printStackTrace();
      }
      else {
      e.printStackTrace();
      }
      }
      catch (Throwable t) {
      System.out.println( "Exception occurred: "
      + t );
      t.printStackTrace();
      }
      }

      /** Validate document using MSV */
      protected void process(Document document, String
      schemaURI) throws Exception {

      System.out.println( "Loaded schema document: "
      + schemaURI );

      // use autodetection of schemas
      VerifierFactory factory =
      VerifierFactory.newInstance("http://www.w3.org/2001/XMLSchema");

      // VerifierFactory factory = new
      com.sun.msv.verifier.jarv.TheFactoryImpl();

      Schema schema = factory.compileSchema(
      schemaURI );

      Verifier verifier = schema.newVerifier();


      // now lets make a DOM object
      DOMWriter domWriter = new DOMWriter();
      org.w3c.dom.Document domDocument =
      domWriter.write(document);
      // domDocument.getDocumentElement().getTagName();
      //domDocument.getEncoding()

      System.out.println( "Converted to DOM tree.
      First tag name is: " +
      domDocument.getDocumentElement().getTagName() );
      try {
      if (verifier.verify(domDocument))
      System.out.println("The document is valid ;-) so
      lets have party");
      else
      System.out.println("The document is
      **********Invalid******** ;-(");
      }catch( com.sun.msv.verifier.ValidityViolation ex)
      {
      System.out.println("The document is
      **********Invalid******** ;-(");
      ex.printStackTrace();
      }



      }
      }





      __________________________________
      Do you Yahoo!?
      Yahoo! SiteBuilder - Free, easy-to-use web site design software
      http://sitebuilder.yahoo.com
    • Kohsuke Kawaguchi
      ... But your stack trace is showing that you are not using MSV. You are using Xerces through my driver program. So I m confused. What s the error? Could you
      Message 2 of 2 , Aug 13, 2003
      • 0 Attachment
        > It does an in-memory dom validation using MSV (dom4j
        > and Xerces as parser and jdk1.4). It works fine for
        > schemas and instances with no namespaces.

        But your stack trace is showing that you are not using MSV. You are
        using Xerces through my driver program.

        So I'm confused. What's the error? Could you post the schema, the
        instance, and the way you launched the program so that I can test it?


        regards,
        --
        Kohsuke Kawaguchi
        Sun Microsystems kohsuke.kawaguchi@...
      Your message has been successfully submitted and would be delivered to recipients shortly.