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));
}
}
|