FileDocCategorySizeDatePackage
Example2.javaAPI DocExample791Fri Feb 01 12:49:14 GMT 2002None

Example2.java

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/**
 * Printing only Character Content (better)
 */
public class Example2 extends DefaultHandler {
    private boolean	ignore = true;

    public void startElement (
	String uri,
	String local,
	String qName,
	Attributes atts
    ) throws SAXException
    {
	if ("line".equals (qName))
	    ignore = false;
    }

    public void endElement (String uri, String local, String qName)
    throws SAXException
    {
	if ("line".equals (qName)) {
	    System.out.println ();
	    ignore = true;
	}
    }

    public void characters (char buf [], int offset, int length)
    throws SAXException
    {
	if (ignore)
	    return;
	System.out.print (new String (buf, offset, length));
    }
}