Code example for SAXParser: Parsing XML documents

Methods: parse, setProperty

0
        throws Exception 
    { 
        SAXParserFactoryImpl spf = new SAXParserFactoryImpl();
        SAXParser sp = spf.newSAXParser();
        MyContentHandler h = new MyContentHandler();
        sp.setProperty(SAXProperty.LEXICAL_HANDLER.toExternal(), (DeclHandler) h);
        InputStream in = new FileInputStream(file);
        sp.parse(new InputSource(in), h);
    } 
 
    /* 
    //////////////////////////////////////////////// 
    // Helper class 
    //////////////////////////////////////////////// 
     */ 
 
    final static class MyContentHandler 
        extends DefaultHandler2
                implements DeclHandler
    { 
        public MyContentHandler() { }