FileDocCategorySizeDatePackage
Skeleton.javaAPI DocExample1551Fri Feb 01 12:50:18 GMT 2002None

Skeleton.java

import java.io.IOException;
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.XMLReaderFactory;


/**
 * SAX2 Application Skeleton
 */
public class Skeleton {

    // argv[0] must be the absolute URL of an XML document
    public static void main (String argv [])
    {
        XMLReader       producer;
        DefaultHandler  consumer;

        // Get an instance of the default XML parser class
        try {
            producer = XMLReaderFactory.createXMLReader ();
        } catch (SAXException e) {
            System.err.println (
                  "Can't get parser, check configuration: "
                + e.getMessage ());
            return;
        }

	// set up the consumer
	try {

	    // Get a consumer for all the parser events
	    consumer = new DefaultHandler ();

	    // Connect the most important standard handler
	    producer.setContentHandler (consumer);

	    // Arrange error handling
	    producer.setErrorHandler (consumer);
	} catch (Exception e) {
	    // consumer setup can uncover errors,
	    // though this simple one shouldn't
	    System.err.println (
	          "Can't set up consumers:"
                + e.getMessage ());
            return;
	}

        // Do the parse!
        try {
            producer.parse (argv [0]);
        } catch (IOException e) {
            System.err.println ("I/O error: ");
	    e.printStackTrace ();
        } catch (SAXException e) {
            System.err.println ("Parsing error: ");
	    e.printStackTrace ();
        }
    }
}