The SAX parser reports events as it parses the components of the XML input, but it does not store the document in any way—it is up to the event handlers to build a data structure. In fact, the DOM parser is built on top of the SAX parser. It builds the DOM tree as it receives the parser events.
Whenever you use a SAX parser, you need a handler that defines the event actions for the various parse events. The
ContentHandler interface defines several callback methods that the parser executes as it parses the document. Here are the most important ones:
endElement are called each time a start tag or end tag is encountered.
characters is called whenever character data are encountered.