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
ISAXXMLReaderinterface.SAXXMLReaderconsumes the XML and throws events to the handlers that you set for the reader. This example creates an instance ofSAXXMLReader, and then sets aContentHandlerand anErrorHandlerfor receiving events from the reader. - IVBSAXContentHandler
- Catches events thrown by the reader. For this application, the
ContentHandlerImplclass implements theIVBSAXContentHandlerinterface. This application highlights the main events received by theContentHandler, includingstartDocument,endDocument,startElement,endElement, andcharacters. - IVBSAXErrorHandler
- Catches any errors raised during the read process. For this application, the
ContentHandlerImplclass also implements theIVBSAXErrorHandlerinterface. At this time, MSXML supports thefatalErrormethod 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 theIVBSAXContentHandlerandIVBSAXErrorHandlerinterfaces; and then sets thecontentHandleranderrorHandlerproperties 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 that implements the
IVBSAXContentHandlerandIVBSAXErrorHandlerinterfaces. When parsing begins, the reader throws a series of events that are received by an instance of theContentHandlerImplclass. For example, for each element in a document, the reader throws thestartElement,characters, andendElementevents. To conditionally output content passed by these events, you add code to the methods in theContentHandlerImplclass. TheContentHandlerImplclass also implements theIVBSAXErrorHandlerinterface, which catches any error events thrown by the reader. At this time, the reader only invokes thefatalErrormethod.
The simple filter application uses the sample XML file, books.xml.
See Also
Application Form | IMXWriter Interface | MXXMLWriter CoClass | ISAXContentHandler Interface | ISAXErrorHandler Interface | Sample XML File (books.xml)
