Skip to main content

Problem with StAXValidatorHelper

No replies
amorlupi
Offline
Joined: 2007-06-06
Points: 0

Hi,

we are using jaxp 1.4.2_20070530 to parse and validate an xml file against an xsd grammar.
Code, we are using, is as follows:

XMLInputFactory factory = XMLInputFactory.newInstance();
try{
// TODO code application logic here
StreamSource stsource = new StreamSource(new FileInputStream(filename));
XMLStreamReader streamReader = factory.createXMLStreamReader(stsource);
Handler handler = new Handler();
SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
schemaFactory.setErrorHandler(handler);

Schema schemaGrammar = schemaFactory.newSchema(new File(schemafilename));

System.out.println("Created Grammar object for schema : " + schemafilename);

Resolver resolver = new Resolver();
//create a validator to validate against grammar sch.
Validator schemaValidator = schemaGrammar.newValidator();
schemaValidator.setResourceResolver(resolver);
schemaValidator.setErrorHandler(handler);
System.out.println("Validating " + filename + " against grammar " + schemafilename);
schemaValidator.validate(new StAXSource(streamReader));

while(streamReader.hasNext()){
System.out.println(streamReader.next());
}

} catch (Exception e) {
// TODO Blocco catch generato automaticamente
e.printStackTrace();
}

We get the following exception:
ERROR: ''
java.lang.NullPointerException
at com.sun.org.apache.xerces.internal.jaxp.validation.StAXValidatorHelper.validate(StAXValidatorHelper.java:95)
at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorImpl.validate(ValidatorImpl.java:114)
at javax.xml.validation.Validator.validate(Validator.java:127)
at teststax.TestStAX.main(TestStAX.java:110)

Any help???

Thank you in advance.

Antonio