Share via


Step 3: Creating the Main Program (Windows Embedded CE 6.0)

1/6/2010

In the final step of this tutorial, you create a main program to accomplish the following actions:

  • Provide a command prompt interface.
  • Create a parser by instantiating a class that implements the SAXXMLReader interface.
  • Create a ContentHandler by instantiating the MyContent class.
  • Register the ContentHandler with the parser.

Example

The following code example shows the complete code for the main program.

Note

To make the following code example easier to read, error checking is not included. This code example should not be used in a release configuration unless it has been modified to include secure error handling.

#include "stdafx.h"

#include "MyContent.h"
#include "SAXErrorHandlerImpl.h"

int main(int argc, char* argv[])
{
   if (argc<2) {
      printf("\nTry something like\n\ttestSax_
      https://server/path/file.xml\n");
      return 0;   // Need URL to read
   }

   CoInitialize(NULL); 
   ISAXXMLReader* pRdr = NULL;

   HRESULT hr = CoCreateInstance(
                        __uuidof(SAXXMLReader), 
                        NULL, 
                        CLSCTX_ALL, 
                        __uuidof(ISAXXMLReader), 
                        (void **)&pRdr);

   if(!FAILED(hr)) 
   {
      MyContent * pMc = new MyContent();
      hr = pRdr->putContentHandler(pMc);

      // No sense to do so in this example, just an illustration how to_
         set other handlers
      //===================================================================================
       SAXErrorHandlerImpl * pEc = new SAXErrorHandlerImpl();
       hr = pRdr->putErrorHandler(pEc);
      // SAXDTDHandlerImpl * pDc = new SAXDTDHandlerImpl();
      // hr = pRdr->putDTDHandler(pDc);


      static wchar_t URL[1000];
      mbstowcs( URL, argv[1], 999 );
      wprintf(L"\nParsing document: %s\n", URL);
      
      hr = pRdr->parseURL(URL);
      printf("\nParse result code: %08x\n\n",hr);
   
      pRdr->Release();
   }
   else 
   {
      printf("\nError %08X\n\n", hr);
   }

   CoUninitialize();
   return 0;
}

You can use this brief introduction to SAX2 as a starting point for writing your own applications.

For more information about the SAX2 interfaces implemented in Windows Embedded CE, see the SAX2 Reference node in the table of contents.

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