Source: loadDOMsmart.cpp

MSXML 5.0 SDK

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

Source: loadDOMsmart.cpp

This C/C++ source code performs the following steps:

  1. Creates an XML DOM object (pXMLDom) and sets it to synchronous mode.
  2. Calls the load method on pXMLDom, specifying the path to stocks.xml.

C/C++ Source File (loadDOMsmart.cpp)

#include <stdio.h>
#import <msxml5.dll>
using namespace MSXML2;

int main(int argc, char* argv[])
{
   IXMLDOMDocument3Ptr pXMLDom;
   HRESULT hr;

   CoInitialize(NULL);
   hr= pXMLDom.CreateInstance(__uuidof(DOMDocument50));
   if (FAILED(hr)) 
   {
      printf("Failed to instantiate an XML DOM.\n");
      return -1;
   }

   pXMLDom->async = VARIANT_FALSE; // default - true,

   if(pXMLDom->load("stocks.xml")!=VARIANT_TRUE)
   {
      printf("Failed to load stocks.xml:\n%s\n",
         (LPCSTR)pXMLDom->parseError->Getreason());
      return -1;
   }
   else
      printf("XML DOM loaded from stocks.xml:\n%s\n", 
         (LPCSTR)pXMLDom->xml);
   pXMLDom.Release();
   CoUninitialize();
   return 0;
}

To add the loadDOMsmart source code to the project

  1. Create a new C++ source file. For detailed instructions on how to do this, see Set Up My Visual C++ Project. Name the new file loadDOMsmart.cpp.
  2. Copy the C/C++ source code above, and paste it into the source file you just created.

Next, we'll add the resource file, stocks.xml.