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 ofSAXXMLReader
, and then sets aContentHandler
and anErrorHandler
for receiving events from the reader. - IVBSAXContentHandler
- Catches events thrown by the reader. For this application, the
ContentHandlerImpl
class implements theIVBSAXContentHandler
interface. 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
ContentHandlerImpl
class also implements theIVBSAXErrorHandler
interface. At this time, MSXML supports thefatalError
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 theIVBSAXContentHandler
andIVBSAXErrorHandler
interfaces; and then sets thecontentHandler
anderrorHandler
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 that implements the
IVBSAXContentHandler
andIVBSAXErrorHandler
interfaces. When parsing begins, the reader throws a series of events that are received by an instance of theContentHandlerImpl
class. For example, for each element in a document, the reader throws thestartElement
,characters
, andendElement
events. To conditionally output content passed by these events, you add code to the methods in theContentHandlerImpl
class. TheContentHandlerImpl
class also implements theIVBSAXErrorHandler
interface, which catches any error events thrown by the reader. At this time, the reader only invokes thefatalError
method.
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)