import org.xml.sax.*; import org.xml.sax.helpers.*; import com.japisoft.fastparser.sax.*; import java.io.*;
/** * Sample of Sax usage. This is a case of FastParser integration without changing * your DOM API usage. This class shows all SAX 2 event during parsing. */ public class Demo implements ContentHandler {
public void setDocumentLocator (Locator locator) { }
public void startDocument() throws SAXException { System.out.println( "- start document" ); }
public void endDocument() throws SAXException { System.out.println( "- end document" ); }
public void startPrefixMapping (String prefix, String uri) throws SAXException { System.out.println( "- startPrefixMapping " + prefix + " / uri=" + uri ); }
public void endPrefixMapping (String prefix) throws SAXException { System.out.println( "- endPrefixMapping " + prefix ); }
public void startElement( String uri, String localName, String qname, Attributes atts) throws SAXException { System.out.println( "* start tag uri=" + uri + " localname=" + localName + " qname=" + qname + " " + atts ); }
public void endElement(String uri, String localName, String qname) throws SAXException { System.out.println( "* end tag uri=" + uri + " localname=" + localName + " qname=" + qname ); }
public void characters(char ch[], int start, int length) throws SAXException { System.out.println( "+ text [" + new String( ch ) + "]" ); }
public void ignorableWhitespace(char ch[], int start, int length) throws SAXException { }
public void processingInstruction(String target, String data) throws SAXException { System.out.println( "! instruction " + target + " " + data ); }
public void skippedEntity( String name ) throws SAXException {
}
public static void main( String[] args ) throws Throwable { System.out.println( "SAX 2 usage sample" ); Sax2Parser p = new Sax2Parser(); p.setContentHandler( new Demo() ); p.parse( new InputSource( new FileInputStream( args[ 0 ] ) ) ); System.exit( 0 ); } }
|