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

public class ContentHandlerPrintAttributes extends DefaultHandler {
    // react on opening elements:
    public void startElement(String url, String localName, String qName,
            Attributes attrs) throws SAXException {
        if (attrs.getLength() > 0) {
            String elementName;
            if (qName == null || qName.equals("")) elementName = localName;
            else elementName = qName;
            System.out.println("element: " + elementName);
            for (int i = 0; i < attrs.getLength(); i++) {
                System.out.println(" - attribute: '" + attrs.getQName(i)
                        + "' value: '" + attrs.getValue(i) + "' type: '"
                        + attrs.getType(i)+"'");
            }
            System.out.println();
    }   }
    // methods for endElement(), startDocument(), endDocument() omitted

    // continue next page


    public void characters(char[] text, int from, int length)
       throws SAXException  {
       // stop evaluation by throwing an exception:
       String textString = (new String(text)).substring(from, from + length);
       if (textString.contains("Göttingen"))
          throw new MySAXTerminatorException();
    }
    // the exception stub:
    public class MySAXTerminatorException extends SAXException { ; }
}
