XML technologies / XML / Python & XML / The Simple API for XML / The origins of SAX

(Excerpt from "Python & XML" by Christopher A. Jones & Fred L. Drake, Jr.)

Before SAX, almost every XML parser had its own interface, so applications were written for specific parsers. These interfaces were simple and generally very similar in structure, differing only in a few details. When new parsers became available, applications had to be substantially revised to work with the new interface and benefit from the new parser, although their basic structure remained essentially unchanged.

As so often, the solution was to introduce another layer. A group of XML developers using Java and led by David Megginson on the XML-DEV mailing list defined a set of Java interfaces that allowed an application to work with any parser. The only requirement was that each parser had a driver for the new API. The driver was a class that used the parser-specific interface to call back into the application through the new common interface. The application created handler objects implementing the methods the driver used for callbacks. When Megginson published the specification, it already included drivers for many popular Java XML parsers. The first specification supported the XML 1.0 Recommendation, but none of the more complex layers built on it; those initiatives were still in their infancy. The developers called the new API “Simple API for XML” or SAX, because it was indeed simpler than most of the parser-specific interfaces it was intended to replace.

The new API was widely welcomed as a major advance for application developers: it was easy to use, allowed applications to work with any parser, and had been carefully designed before any other common API was available. Java programmers were especially pleased because it considerably reduced the stress of their work. Developers using other languages adopted the specification in ways that preserved SAX’s identity as an API while accommodating their languages’ conventions. Python programmers in the XML-SIG, led by Lars Marius Garshol, adapted the API and implemented drivers for several parsers. This implementation eventually became part of the PyXML package.

Then the W3C published the namespace Recommendation, changing the entire concept of what constitutes a name. Despite much debate about its value, most people recognized that it solved real problems and was here to stay. Nobody wanted to struggle with incompatible APIs again, so the SAX developers quickly joined forces to create a version supporting Namespaces. The revised API is also known as SAX2. Interestingly, some of the first namespace implementations were filters written as SAX handlers. SAX events were used to drive SAX2 handlers, with some processing in between to add support for namespace.

Python developers quickly adopted the SAX2 interface, resolving some inconsistencies in the earlier mapping of SAX from its Java-based specification. The SAX2 API soon became part of PyXML and was also included in the Python standard library. When Python programmers refer to the SAX API, they generally mean this second version.

  

 

 

 

back to top