Processing XML with SAX

SAX is the de facto standard XML parser interface for Java. You learn how to use it here with a simple SAX application written in Java.

The Simple API for XML (SAX) is a streaming, event-based API for XML ( It was (and continues to be) developed by members of the xml-dev mailing list ( Discussion of a uniform API for XML parsers began on xml-dev in December 1997 ( and resulted in the release of the first version of SAX in May 1998 (, with David Megginson as the chief maintainer ( SAX 2.0.1, which has namespace support, was released in January 2002, with David Brownell as the lead maintainer (

SAX provides an interface to SAX parsers. As an event -based API, it munches on documents and reports, parsing events along the way, usually in one fell swoop. These reports come directly to the application through callbacks. This is called push parsing . To push these events, an application must implement event handlers (methods) from the SAX interfaces, such as startDocument() or startElement(). Without implementing or registering these handlers, a SAX application won’t “see” the results that are pushed up from its underlying parser.


Pull parsing , on the other hand, allows you to pull events on demand. ...

Get XML Hacks now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.