May 22, 2011, 3:06 p.m.
posted by equivalent
SAX, the Simple API for XML, is a Java native, parser-independent, event-based API for processing XML documents, suitable for use with very large documents and streaming data. SAX is organized mostly around interfaces. The implementation classes vary from one parser to the next.
The two key SAX interfaces are XMLReader, which represents the parser; and ContentHandler, through which the parser communicates with the client application. The client application registers its specific instance of the ContentHandler interface with an XMLReader through the setContentHandler() method. Then, as the XMLReader parses documents, it calls back to the methods in the ContentHandler object.
Only in the simplest programs do these callback methods give you all of the information you want when you want it. Most of the time it's necessary to gradually fill one or more data structures as the document is parsed. The complexity of any SAX program is largely a function of the complexity of the data structures you need to build.