3.4.8 Coding example for using the high-speed parse support function

An example of code described in the user program for using the high-speed parse support function is as follows:

import java.io.File;
import java.io.IOException;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.SAXParser;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import com.cosminexus.jaxp.preparsedxml.PreparsedObjectFactory;
import com.cosminexus.jaxp.preparsedxml.PreparsedObject;

public class TestSAXParser{
public static void main(String[] args){
try{
 // Generate the preparsed object from the Pre-Parse XML document
 File xml = new File("learning1.xml");
 MyHandler handler = new MyHandler ();
 PreparsedObjectFactory pof = PreparsedObjectFactory.newInstance();
 pof.setNamespaceAware(true);
 pof.setEntityResolver(handler);
 pof.setErrorHandler(handler);
 PreparsedObject pobj = pof.newPreparsedObject(xml);

 // Generate the XML parser
 SAXParserFactory spf = SAXParserFactory.newInstance();
 spf.setNamespaceAware(true);
 SAXParser sp = spf.newSAXParser();

 // Set up the preparsed object in the XML parser, and parse
 sp.setProperty("http://cosminexus.com/xml/properties/preparsedobject-load", pobj);
 sp.parse("SampleSAX.xml", handler);
} catch(IllegalArgumentException iae){
 System.out.println("MSG : " + iae.getMessage());
}catch(SAXException se){
 System.out.println("MSG : " + se.getMessage());
}catch(IOException ioe){
 System.out.println("MSG : " + ioe.getMessage());
}catch(Exception e){
 e.printStackTrace();
}
}
}

class MyHandler extends DefaultHandler {
//Describe the implementation of the error handler and entity resolver
}