Compartilhar via


Step 1: Creating the Header File

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

The first step of creating a SAX2 application is to implement handler classes. When you use SAX2, the most useful handler class is ContentHandler. You derive this class from the ISAXContentHandler interface.

To use the SAX2 interfaces that come with MSXML, you need to declare them using the following code example.

#include <msxml2.h>

Note

For the JumpStart application, declare the interfaces in the StdAfx.h file.

Example

The following code example shows how to create the header file, named MyContent.h. This file is required to implement the ContentHandler.

#include "SAXContentHandlerImpl.h"

class MyContent : public SAXContentHandlerImpl  
{
public:
    MyContent();
    virtual ~MyContent();
        
        virtual HRESULT STDMETHODCALLTYPE startElement( 
        // Receives notification of the beginning of an element. 
        // The reader invokes the startElement method at the beginning of every element in the XML document.

            wchar_t __RPC_FAR *pwchNamespaceUri, //in, the namespace URI
            int cchNamespaceUri,                 //in, the length of the namespace URI
            wchar_t __RPC_FAR *pwchLocalName,    //in, the local name string.
            int cchLocalName,                   //in, the length of the local name string
            wchar_t __RPC_FAR *pwchQName,       //in, the XML 1.0 qualified name (QName), with prefix, 
                                                //or, an empty string (if QNames are not available).
            int cchQName,                       //in, the length of the QName
            ISAXAttributes __RPC_FAR *pAttributes); //in, the attributes attached to the element
        
        virtual HRESULT STDMETHODCALLTYPE endElement( 
        // Receives notification of the end of an element. 
        // The reader invokes this method at the end of every element in the XML document.

            wchar_t __RPC_FAR *pwchNamespaceUri, //in, the namespace URI
            int cchNamespaceUri,                 //in, the length of the namespace URI
            wchar_t __RPC_FAR *pwchLocalName,    //in, the local name string.
            int cchLocalName,                   //in, the length of the local name string
            wchar_t __RPC_FAR *pwchQName,       //in, the XML 1.0 qualified name (QName), with prefix, 
                                                //or, an empty string (if QNames are not available).
            int cchQName);                      //in, the length of the QName

        virtual HRESULT STDMETHODCALLTYPE startDocument();
        // Receives notification of the beginning of a document. 
        // The reader invokes the startDocument method only once.


private:
        void prt(
        // conversion method for output
        // converts element specified by pwchVal to the format specified by pwchFmt
            const wchar_t * pwchFmt,          //in, format for output
            const wchar_t __RPC_FAR *pwchVal, // in, element to be converted
            int cchVal);                      // in, length of element to be converted
      int idnt; // current depth in document tree, that is, number of unclosed elements encountered
};

#endif // !defined(AFX_MYCONTENT_H__E1B3AF99_0FA6_44CD_82E3_55719F9E3806__INCLUDED_)

See Also

Tasks

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

Concepts

Step 2: Creating the MyContent Class
Getting Started with SAX2
SAX2 Developer Guide