DefaultHandler
Extend the DefaultHandler class to use event handling methods such as as startDocument, endDocument, startElement, endElement, and characters.
public class Echo extends DefaultHandler { ... }DefaultHandler also defines methods events in the DTDHandler, EntityResolver, and ErrorHandler interfaces.
All methods must throw a SAXException, which is sent back to the parser, which then sends it on to the code that invoked the parser. In the current program, that means it winds up back at the Throwable exception handler at the bottom of the main method.
When a start tag or end tag is encountered, the name of the tag is passed as a String to the startElement or endElement method, as appropriate. When a start tag is encountered, any attributes it defines are also passed in an Attributes list. Characters found within the element are passed as an array of characters, along with the number of characters (length) and an offset into the array that points to the first character.