An application handles these events just as it would handle events from a graphical user interface; there is no need to cache the entire document in memory or secondary storage.

Currently, there are two versions of SAX: 1.0 and 2.0. Many changes were made in version 2.0. The focus of this chapter is on SAX version 2.0. Most SAX parsers should support the older 1.0 classes and interfaces, however, you will receive deprecation warnings from the Java complier if you use these older features.

SAX2 classes and interfaces

The following interfaces and classes are provided by SAX2:

￿org.xml.sax.XMLReader which replaces SAX1 Parser

￿org.XML.sax.XMLFilter

￿org.xml.sax.ContentHandler which replaces SAX1 DocumentHandler

￿org.xml.sax.Attributes which replaces SAX1 AttributeList

￿org.xml.sax.SAXNotSupportedException

￿org.xml.sax.SAXNotRecognizedException

￿org.xml.sax.helpers.AttributesImpl which replaces SAX1 AttributeListImp

￿org.xml.sax.helpers.NamespaceSupport

￿org.xml.sax.helpers.XMLFilterImpl

￿org.xml.sax.helpers.ParserAdapter

￿org.xml.sax.helpers.XMLReaderAdapter

￿org.xml.sax.helpers.DefaultHandler which replaces SAX1 HandlerBase

SAX2 contains complete namespace support, which is available by default from any XMLReader. AN XML reader can also optionally supply raw XML 1.0 names. Have a look at “XML namespace support” on page 61 for more details about SAX2 support for XML namespaces.

The ContentHandler and Attribute interfaces are similar to the deprecated DocumentHandler and AttributeList interfaces, but they add support for the namespace related information. ContentHandler also adds a callback for skipped entities, and Attributes adds the ability to look up an attribute’s index by name.

The ContentHandler interface is regarded as the most important of the all, as it has methods such as startDocument(), startElement(), characters(), endElement(), and endDocument(). During the parsing process, startDocument() is called once, then startElement() and endElement() are called once for each tag in the XML data. The characters() method provides the text value of the element. This process continues until the end of the document, at which time endDocument() is called.

Since ContentHandler is an interface, it is up to your application code to somehow implement this interface and subsequently do something when the parser invokes its methods. SAX does provide a class called DefaultHandler that

60 The XML Files: Development of XML/XSL Applications Using WebSphere Studio

Page 76
Image 76
IBM Version 5 manual SAX2 classes and interfaces