Creating the Header File

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - SAX2 Developer's Guide

Creating the Header File

When it comes to using the Simple API for XML (SAX2), the most useful handler class is the ContentHandler. You derive this class from the ISAXContentHandler interface.

To use the SAX2 interfaces in Microsoft® XML Core Services (MSXML) 5.0 for Microsoft Office, you must declare them with the following code. The following shows importing msxml5.dll.

#import <msxml5.dll> raw_interfaces_only 
using namespace MSXML2;
Note   For the JumpStart application, you declare the interfaces in the StdAfx.h file.

To implement the ContentHandler, create the header file, named "MyContent.h", as shown in the following sample code.

#include "SAXContentHandlerImpl.h"

class MyContent : public SAXContentHandlerImpl  
{
public:
    MyContent();
    virtual ~MyContent();
        
        virtual HRESULT STDMETHODCALLTYPE startElement( 
            /* [in] */ wchar_t __RPC_FAR *pwchNamespaceUri,
            /* [in] */ int cchNamespaceUri,
            /* [in] */ wchar_t __RPC_FAR *pwchLocalName,
            /* [in] */ int cchLocalName,
            /* [in] */ wchar_t __RPC_FAR *pwchQName,
            /* [in] */ int cchQName,
            /* [in] */ ISAXAttributes __RPC_FAR *pAttributes);
        
        virtual HRESULT STDMETHODCALLTYPE endElement( 
            /* [in] */ wchar_t __RPC_FAR *pwchNamespaceUri,
            /* [in] */ int cchNamespaceUri,
            /* [in] */ wchar_t __RPC_FAR *pwchLocalName,
            /* [in] */ int cchLocalName,
            /* [in] */ wchar_t __RPC_FAR *pwchQName,
            /* [in] */ int cchQName);

        virtual HRESULT STDMETHODCALLTYPE startDocument();

private:
        void prt(
            /* [in] */ const wchar_t * pwchFmt,
            /* [in] */ const wchar_t __RPC_FAR *pwchVal,
            /* [in] */ int cchVal);
      int idnt;
};

#endif // !defined(AFX_MYCONTENT_H__E1B3AF99_0FA6_44CD_82E3_55719F9E3806__INCLUDED_)