FileDocCategorySizeDatePackage
TestSAXParsing.javaAPI DocExample4944Wed Sep 19 09:17:02 BST 2001javaxml2

TestSAXParsing

public class TestSAXParsing extends Object

TestSAXParsing is a simple class that demonstrates how JAXP can be used to work with SAX (the Simple API for XML).

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

Provide a static entry point.

        try {
            if (args.length != 1) {
                System.err.println ("Usage: java TestSAXParsing [filename]");
                System.exit (1);
            }

            // Get SAX Parser Factory
            SAXParserFactory factory = SAXParserFactory.newInstance();

            // Turn on validation, and turn off namespaces
            factory.setValidating(true);
            factory.setNamespaceAware(false);

            SAXParser parser = factory.newSAXParser();
            parser.parse(new File(args[0]), new MyHandler());

        } catch (ParserConfigurationException e) {
            System.out.println("The underlying parser does not support the requested features.");
        } catch (FactoryConfigurationError e) {
            System.out.println("Error occurred obtaining SAX Parser Factory.");
        } catch (Exception e) {
            e.printStackTrace();
        }