The Simple API for XML (SAX2) is a push-model parser. When SAX2 parses a document, the SAXXMLReader
(reader) reads the document and passes a series of events to the implemented event handlers. The SAX2 reader generates several categories of events, including:
To handle such events, you implement a corresponding handler class that contains methods to process the appropriate events. You implement handlers only for those events you wish to process. If you do not implement a handler for a specific type of event, the reader simply ignores that event.
The JumpStart application covered in this section contains the three components that you most often implement for SAX2 applications in Microsoft® Visual Basic®.
Component | Description |
---|---|
ContentHandler |
Implements the IVBSAXContentHandler interface. The ContentHandler is a class that provides methods for processing the main content of an XML document. When SAX2 parses a document, the reader passes a series of events to the ContentHandler . For example, for each element in a document, the reader passes the startElement , characters , and endElement events. To handle these events, you add code to the methods in the ContentHandler to process the information passed by the reader. |
ErrorHandler |
Implements the IVBSAXErrorHandler interface. The ErrorHandler is a class that provides methods for processing error events passed by the reader. At this time, the reader invokes the fatalError method only. |
main form | Provides the user interface for the application. This consists of two text boxes, one for entering a file name and another for displaying results. This interface also has Parse and Exit buttons. In addition to providing the user interface, the main form also contains code that creates instances of the SAXXMLReader , ContentHandler , and ErrorHandler ; sets the handler classes to the reader; sets the source for parsing the document; and starts the parse operation. |