Compartilhar via


Tutorial: JumpStart for Creating a SAX2 Application with C++

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

You can quickly build a basic C++ application that reads an XML document and prints the document's tags to the console.

This tutorial will give you a quick introduction to how the Microsoft® XML Parser (MSXML) for Windows Embedded CE implementations of SAX2, and help you begin building applications using the SAX2 interfaces.

Overview of the JumpStart Application

SAX2 is a push-model parser. When SAX2 parses a document, the SAXXMLReader reads the document and passes a series of events to the event handlers that you choose to implement.

The reader generates the following categories of events:

  • Those that occur in the content of an XML document
  • Those that occur in the document type definition (DTD)
  • Those that occur as errors

To handle these events, implement a corresponding handler class that contains methods to process the appropriate events. You have to implement handlers only for those events that you wish to process. If you do not implement a handler for a specific type of event, the reader ignores that event.

The following table shows the two main pieces that you need to implement for the JumpStart application covered in this tutorial.

Functionality Description

ContentHandler

Implements the ISAXContentHandler 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 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.

main program

  • Creates an instance of ISAXXMLReader.
  • Creates an instance of the ContentHandler.
  • Sets the ContentHandler to the reader.
  • Sets the source for the XML document.
  • Starts the parsing process.

To create the JumpStart application, you must first implement a handler class extending the ISAXContentHandler interface. With C++, you can create a class and not a full-featured COM object. The methods of this class tell the application what to do when it receives notification of an event.

After you implement the ContentHandler class, you create the main program that creates an instance of the SAXXMLReader, sets the ContentHandler, and starts the parse operation.

Tutorial Prerequisites

To complete this tutorial, you will need a Windows Embedded CE–based device with the XML SAX Catalog item included.

In this tutorial, you will complete the following steps:

See Also

Concepts

SAX2 Developer Guide
Getting Started with SAX2