473,416 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Beginner's problem when using jing Relax NG validator through JARVinterface


I am trying to learn to use jing through JARV interface and I have read
JARV User's Guide (http://iso-relax.sourceforge.net/JARV/JARV.html).
I have downloaded jingjarv-examples.zip from JARV User's Guide page and
latest jing version 20030619 from jing home page.

I can run jing successfully from command line like this (which I guess
proves that schema should be correct)

C:\Temp\APU> java -jar jing.jar schema.xsd valid.xml

C:\Temp\APU> java -jar jing.jar schema.xsd invalid.xml
C:\Temp\APU\invalid.xml:4:12: error: required elements missing

But for some reason I don't get any java program to perform validation
using JARV interface. For example if I try to run precompiled
SingleThreadDriver that comes in jingjarv-examples.zip package this is
what happens.

C:\Temp\APU>java SingleThreadDriver schema.xsd valid.xml
driver is com.thaiopensource.relaxng.jarv.VerifierFactoryImp l

C:\Temp\APU>java SingleThreadDriver schema.xsd invalid.xml
driver is com.thaiopensource.relaxng.jarv.VerifierFactoryImp l

So it doesn't throw any exception but it doesn't print any messages
either after finding driver (Of course I don't know if this class is
compiled from same source code that is included in package).

I can successfully compile the SingleThreadDriver.java by myself but
after that the class throws java.lang.NullPointerException if I try to
run it. I have added few debug printing lines to the code to locate the
source of the exception (I have added the modified
SingleThreadDriver.java, schema.xsd, valid.xml and invalid.xml files to
the end of the message). So this is what happens:

C:\Temp\APU>set CLASSPATH

CLASSPATH=C:\APPS\j2sdk1.4.1_03\lib\tools.jar;.\ji ng.jar;.\isorelax.jar;.\saxon.jar;.\xercesImpl.jar ;.\xml-apis.jar;.

C:\Temp\APU>javac SingleThreadDriver.java

C:\Temp\APU>java SingleThreadDriver schema.xsd invalid.xml
driver is com.thaiopensource.relaxng.jarv.VerifierFactoryImp l
parsing schema.xsd
schema != null
Exception in thread "main" java.lang.NullPointerException
at
com.thaiopensource.relaxng.jarv.VerifierHandlerImp l.reset(Unknown Source)
at
com.thaiopensource.relaxng.impl.PatternValidator.< init>(Unknown Source)
at
com.thaiopensource.relaxng.jarv.VerifierHandlerImp l.<init>(Unknown Source)
at
com.thaiopensource.relaxng.jarv.VerifierImpl.<init >(Unknown Source)
at
com.thaiopensource.relaxng.jarv.SchemaImpl.newVeri fier(Unknown Source)
at SingleThreadDriver.main(SingleThreadDriver.java:39 )

The NullPointerException occurs in this line

Verifier verifier = schema.newVerifier();

and based on the debug printing at least schema object is not null so
exception must occur inside newVerifier method.

So finally the actual question. Do you know based on my explanation what
goes wrong? Can I use jing alone directly from java program or do I need
some other libraries than what comes in jing-20030619.zip package
(isorelax.jar, jing.jar, saxon.jar, xercesImpl.jar, xml-apis.jar)?

One thing that I noticed is that there is different namespace URI used
in SingleThreadDriver.java and schema.xsd (I copied schema example from
internet). I tried to change these URIs also but I didn't notice any
effects with changing the URIs to match each other.

And here are the example files:
-------------------------------

---SingleThreadDriver.java starts after this line---

import org.iso_relax.verifier.*;
import java.io.File;

public class SingleThreadDriver
{
public static void main( String[] args ) throws Exception {
if(args.length<1) {
System.out.println("SingleThreadDriver <schema> <document>
....");
return;
}

// find a JARV implementation. This will find JingJarv if
// it is in the classpath.
VerifierFactory factory = VerifierFactory.newInstance(
"http://relaxng.org/ns/structure/0.9");
if(factory==null) {
System.out.println("No JARV implementation found");
return;
}

System.out.println("driver is "+factory.getClass().getName());

// use VerifierFactory to compile schemas.
// if errors are found in the schema, an exception will be thrown.
// thus in a real application, you should catch it.
System.out.println("parsing "+args[0]);
Schema schema = factory.compileSchema(new File(args[0]));

// TEST!!! Check if schema is null and thus causes null pointer
exception
if (schema == null) {
System.out.println("schema == null");
} else {
System.out.println("schema != null");
}

// the newVerifier method will create a Verifier object,
// which will perform actual validation.
Verifier verifier = schema.newVerifier();

// TEST!!! Test if we succeeded to create new Verifier
System.out.println("Did we reach this point?");

for( int i=1; i<args.length; i++ ) {
System.out.println("validating "+args[i]);

// validate documents
if( verifier.verify(new
File(args[i]).toURL().toExternalForm()) )
System.out.println("valid");
else
System.out.println("invalid");
}
}
}

---schema.xsd starts after this line---
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<start>
<element name="addressBook">
<zeroOrMore>
<element name="card">
<element name="name">
<text/>
</element>
<element name="email">
<text/>
</element>
</element>
</zeroOrMore>
</element>
</start>
</grammar>

---valid.xml starts after this line---
<?xml version="1.0" encoding="UTF-8"?>
<addressBook>
<card>
<name>John Smith</name>
<email>js@example.com</email>
</card>
<card>
<name>Fred Bloggs</name>
<email>fb@example.net</email>
</card>
</addressBook>

---invalid.xml starts after this line---
<?xml version="1.0" encoding="UTF-8"?>
<addressBook>
<card>
<email>js@example.com</email>
</card>
<card>
<name>Fred Bloggs</name>
<email>fb@example.net</email>
</card>
</addressBook>

Jul 20 '05 #1
0 3696

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ducky Sherwood | last post by:
Aahz wrote: >Before the meeting, we'll continue the tradition started last month and >meet at 6pm for dinner, somewhere around downtown Palo Alto. Ducky >Sherwood is handling that; please send...
6
by: Pieter | last post by:
I've read a lot of posts on "why relax ng is so very good" and on "why w3c xml schema should be the only schema language". I'm, however, still not clear on why I should prefer one over the other. ...
2
by: Colin | last post by:
Hi, I am having some trouble using css correctly and I was wondering if a subscriber to this newsgroup might be able to offer some suggestions. The problem refers to the page ...
2
by: Stephen | last post by:
Can I reference another style as a definition for a style? Such as... ..footerlink { font-size: 9px;} ..headerlink { font-size: .footerlink.fontsize } .... so that I can just change the...
8
by: Jing Cheng | last post by:
Hi, I'm using ifstream reading data from a file, as following: ifstream finput("track.dat"); if(finput.fail()){ cerr << "Open input DATA file error!\n"; exit(-1);
5
by: redsoxnut | last post by:
Can someone take a look at http://www.grooveswitch.com and help me figure out what's causing the misalignment? I just converted my entire site to a tableless design and am hung up on this final...
13
by: jcsnippets.atspace.com | last post by:
Hi everybody, A few days ago I decided to get my site validated, so I have begun to clean up the first page to get an impression of what I should and should not do. To be able to get the site...
1
by: Gerben Abbink | last post by:
Hi, Accoring to the specs (http://www.thaiopensource.com/relaxng/nrl.html), it should be possible to use Namespace Routing Language (NLR) with Jing ("A sample implementation of NRL is included...
1
by: Torsten Munkelt | last post by:
Hi, I want to validate an XML document applying a combination of RELAX NG and Schematron. I have not found an appropriate validator. Would you please send me links to such validators. I would...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.