Share via


Overview of the Simple Filter Application

 

The simple filter application contains the building blocks of almost all SAX applications, including:

SAXXMLReader
CoClass that implements the ISAXXMLReader interface. SAXXMLReader consumes the XML and throws events to the handlers that you set for the reader. This example creates an instance of SAXXMLReader, and then sets a ContentHandler and an ErrorHandler for receiving events from the reader.

IVBSAXContentHandler
Catches events thrown by the reader. For this application, the ContentHandlerImpl class implements the IVBSAXContentHandler interface. This application highlights the main events received by the ContentHandler, including startDocument, endDocument, startElement, endElement, and characters.

IVBSAXErrorHandler
Catches any errors raised during the read process. For this application, the ContentHandlerImpl class also implements the IVBSAXErrorHandler interface. At this time, MSXML supports the fatalError method only.

This application consists of two main parts.

Application form
Provides the user interface for the application. This consists of three text boxes: one for entering a file name; one for entering an element name; and the other for displaying results. The form also has Parse and Exit buttons. Pressing Parse creates an instance of the SAXXMLReader; creates an instance of the class implementing the IVBSAXContentHandler and IVBSAXErrorHandler interfaces; and then sets the contentHandler and errorHandler properties of the reader to point to the class. Pressing Parse also sets the filter criteria in the content handler, sets the input for the reader, and starts the parse operation.

ContentHandlerImpl
A class thatimplements the IVBSAXContentHandler and IVBSAXErrorHandler interfaces. When parsing begins, the reader throws a series of events that are received by an instance of the ContentHandlerImpl class. For example, for each element in a document, the reader throws the startElement, characters, and endElement events. To conditionally output content passed by these events, you add code to the methods in the ContentHandlerImpl class. The ContentHandlerImpl class also implements the IVBSAXErrorHandler interface, which catches any error events thrown by the reader. At this time, the reader only invokes the fatalError method.

The simple filter application uses the sample XML file, books.xml.

See Also

Application Form (Simple Filter)
IMXWriter Interface
MXXMLWriter CoClass
ISAXContentHandler Interface
ISAXErrorHandler Interface
Sample XML File (books.xml)