Article:
  XML Document Validation with an XML Schema
Subject:   Null Pointer exception while running
Date:   2005-12-18 20:53:08
From:   NehaK
Hi


I have already set these 2 jars(jaxp-api.jar and xercesImpl.jar) in the classpath. This is the code what u have given for validation with JAXP. I have modified only the main function where i am hardcoding the schema and document path. Could it be because of some problem with jdk vesion or some problem with the jdk installation? I have recently installed jdk frim from java.sun.com. follwoing are the details of the jsk version.


Windows Platform - J2SE(TM) Development Kit 5.0 Update 6
Windows Offline Installation, Multi-language jdk-1_5_0_06-windows-i586-p.exe 59.86 MB



Please help me in resolving the issue.


import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.xml.sax.ErrorHandler;


public class JAXPValidator
{
public void validateSchema(String SchemaUrl, String XmlDocumentUrl)
{
try
{
System.out.println("
Inside JAXPValidator");
System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
"org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
System.out.println("
After DocumentBuilderFactory");


factory.setNamespaceAware(true);
factory.setValidating(true);
System.out.println("
Values set After DocumentBuilderFactory");


factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
"http://www.w3.org/2001/XMLSchema" );
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource",SchemaUrl);
System.out.println("
Attributes set After DocumentBuilderFactory");


DocumentBuilder builder =factory.newDocumentBuilder();
System.out.println("
After DocumentBuilder");


Validator handler=new Validator();
builder.setErrorHandler(handler);
System.out.println("
After Validator");


builder.parse(XmlDocumentUrl);
System.out.println("
After builder.parse");


if(handler.validationError==true)
System.out.println("XML Document has Error:"+handler.validationError+" "+handler.saxParseException.getMessage());
else
System.out.println("XML Document is valid");
}
catch(java.io.IOException ioe)
{
System.out.println("IOException "+ioe.getMessage());
}
catch (SAXException e)
{
System.out.println("SAXException"+e.getMessage());
}
catch (ParserConfigurationException e)
{
System.out.println("ParserConfigurationException " + e.getMessage());
}
}
private class Validator extends DefaultHandler
{
public boolean validationError =false;
public SAXParseException saxParseException=null;
public void error(SAXParseException exception) throws SAXException
{
validationError = true;
saxParseException=exception;
}
public void fatalError(SAXParseException exception) throws SAXException
{
validationError = true;
saxParseException=exception;
}
public void warning(SAXParseException exception) throws SAXException
{ }
}
public static void main(String[] argv)
{
String SchemaUrl = "file:/C:/PServer/server/nodes/default/archives/public_html/reportinfra/WEB-INF/properties/ReportQueries.xsd";
String XmlDocumentUrl = "fike:/C:/PServer/server/nodes/default/archives/public_html/reportinfra/WEB-INF/properties/ReportSqlQueries.xml";


JAXPValidator validator=new JAXPValidator();
validator.validateSchema(SchemaUrl, XmlDocumentUrl);
}
}



Thanks & Regards
Neha


Full Threads Newest First

Showing messages 1 through 1 of 1.

  • Null Pointer exception while running
    2005-12-19 08:32:20  Deepak Vohra | [View]

    The application in the tutorial was developed with JDK 1.4.2. Please use JDK 1.4.2.