Simple API for XML (SAX), an event-driven XML API, defines a stream of events specifying XML structure as handed from the parser to the specialized handler code. Discover how SAX originated, and learn why it's considered to be one of the most efficient, yet one of the most difficult, ways to process XML.
Simple API for XML (SAX) [community specification] is an event-driven API. You register handler code for specific events that are triggered by different parts of XML markup (such as start and end tags, text, and entities). The parser then sends a stream of these events based on the input XML, which the handler code processes in turn.
SAX was essentially created on a marathon thread starting in late 1997 on the XML-DEV mailing list, which has long been the prime habitat for XML experts. David Megginson led the discussion, and the result was one of the most successful XML initiatives, with no large company or standards-body sponsorship. Before SAX, each parser had its own peculiar API for communicating XML structure to handler code, and SAX provided important unification. In general, parsers provide SAX drivers that translate low-level parser events into SAX standard events, allowing for portable code. SAX was developed with the Java™ language in mind, but it has become popular across numerous languages and environments, although sometimes its Java-centricity complicates porting. SAX is currently in its second generation, which includes XML namespace processing and optional reporting of certain events relating to document structure.
In mainstream languages, event-based interfaces are usually implemented using callback functions, a style familiar in graphical user interface (GUI) programming and the like. In object- oriented languages, callbacks are usually registered methods for an object, using polymorphism to match the method name to the handler code, and using encapsulation to manage state in the handler between callbacks. This overall model of event-based programming is known as a push model and has a reputation for being difficult for many programmers to master. Most models that are considered easier to program, however, require random access to the document, and thus can lead to inefficiencies, so SAX has the reputation for being the most efficient standard way to process XML, if far from the easiest.
- Start with the tutorial Understanding SAX by Nicholas Chase (developerWorks, July 2003).
- Benoit Marchal's article SAX, the power API introduces the basic concepts of XML APIs, introduces SAX, and compares Document Object Model (DOM) and SAX (developerWorks, August 2001).
- C++ developers should read The Joy of SAX: a Visual Basic Sample by Martin Naughton (MSDN, June 2000).
- Perl programmers should check out Using Perl with XML (Part 1), which covers SAX.
- Read about other XML standards: Index of XML standards.
- Participate in any of several XML-centered forums: XML zone discussion forums.
- Get involved in the developerWorks community: developerWorks blogs
- Find out how you can become an IBM-Certified Developer in XML and related technologies at IBM XML certification.
- See the developerWorks XML Zone for a wide range of technical articles and tips, tutorials, standards, and IBM Redbooks at XML technical library.
- Stay current with technology in these sessions: developerWorks technical events and webcasts.
- Build your next development project with trial software available for download directly from developerWorks: IBM trial software