I am trying to parse a small xml file using SAX parser.
I am using the following code
package com.nortel.nimo.logic;
import java.io.*;
import org.xml.sax.*;
import org.xml.sax.helpers.XMLReaderFactory;
import org.xml.sax.helpers.DefaultHandler;
import org.apache.xerces.parsers.SAXParser;
public class OutputGenerator extends DefaultHandler{
private File billFile;
private PrintWriter out;
public static void main (
String args[])throws Exception{
OutputGenerator outGen = new OutputGenerator(new File("C:/nortelsax/test/acct.xml"), new PrintWriter(new BufferedWriter(new FileWriter("C:/nortelsax/test/output.xml"))));
//System.setProperty(org.xml.sax.helpers.XMLReaderFactory, com.nortel.nimo.logic.OutputGenerator);
}
public OutputGenerator(File _billFile, PrintWriter _out) {
this.billFile = _billFile;
this.out = _out;
// OutputGenerator handler = new OutputGenerator();
createPreprocessedOutput(this.billFile, this.out);
}
public OutputGenerator(){
}
public static synchronized String createPreprocessedOutput(File billFile, PrintWriter out) {
try {
XMLReader xr = XMLReaderFactory.createXMLReader();
OutputGenerator handler = new OutputGenerator();
xr.setContentHandler(handler);
xr.setErrorHandler(handler);
FileReader r = new FileReader(billFile);
xr.parse(new InputSource(r));
System.out.println(billFile + " is well-formed.");
}
catch (SAXException e) {
System.out.println(billFile + " is not well-formed." + e.getMessage());
}
catch (IOException e) {
System.out.println("Due to an IOException, the parser could not check " + billFile);
}
return "success";
}
public void startDocument ()
{
System.out.println("Start document");
}
public void endDocument ()
{
System.out.println("End document");
}
public void startElement (String uri, String name,
String qName, Attributes atts)
{
if ("".equals (uri))
System.out.println("Start element: " + qName);
else
System.out.println("Start element: {" + uri + "}" + name);
}
public void endElement (String uri, String name, String qName)
{
if ("".equals (uri))
System.out.println("End element: " + qName);
else
System.out.println("End element: {" + uri + "}" + name);
}
}
I am getting an error, it says system property org.xml.sax.driver not specified. Is driver something that we need to include, wHAT IS DRIVER
HOW DO WE INCLUDE IT??
Can anyone explain it to me.