FileDocCategorySizeDatePackage
Example3.javaAPI DocExample814Fri Feb 01 12:49:34 GMT 2002None

Example3.java

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import java.util.Stack;


/**
 * Printing only Character Content (element stack)
 */
public class Example3 extends DefaultHandler {
    private Stack	stack = new Stack ();

    public void startElement (
	String uri,
	String local,
	String qName,
	Attributes atts
    ) throws SAXException
    {
	stack.push (qName);
    }

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

    public void characters (char buf [], int offset, int length)
    throws SAXException
    {
	if (!"line".equals (stack.peek ()))
	    return;
	System.out.print (new String (buf, offset, length));
    }
}