Re: MSXML and VS2005
"saywhat" <no@fuk.no> wrote in message news:M1Ovg.991$OZ7.510@fe06.lga...
I am using VS2005, and was wondering where I could find a wrapper class for
MSXML. There was one on Codeguru (or code project, dont remeber) but it
wouldn't comlpile. TIA
Why do you need a wrapper class? Just use the ATL smart pointer classes and
the #import directive. Here's a quick sample that I had whipped up for
someone some time ago...
-Pete
#include "stdafx.h"
#import <msxml4.dll>
#include <iostream>
#include <cstdlib>
#ifdef UNICODE
#define _tout wcout
#else
#define _tout cout
#endif
int _tmain(int argc, _TCHAR* argv[])
{
HRESULT hr = ::CoInitialize ( NULL );
if (SUCCEEDED ( hr ) )
{
MSXML2::IXMLDOMDocument2Ptr pDomDocument;
hr = pDomDocument.CreateInstance (__uuidof (MSXML2::DOMDocument40));
if (SUCCEEDED (hr))
{
pDomDocument->async = VARIANT_FALSE ;
pDomDocument->validateOnParse = VARIANT_TRUE;
pDomDocument->resolveExternals = VARIANT_TRUE;
if ( VARIANT_TRUE == pDomDocument->load (
_T("http://rss.slashdot.org/Slashdot/slashdot") ) )
{
std::_tout << _T("Success") << std::endl;
// To prove to yourself that the file actually was downloaded, save it
locally.
pDomDocument->save ( _T("Downloaded.xml") );
}
else
{
MSXML2::IXMLDOMParseErrorPtr pError = NULL;
if ((pError = pDomDocument->parseError) != NULL)
{
hr = pError->errorCode;
std::_tout << _T("Error Code: ") << pError->errorCode << std::endl;
std::_tout << _T("Reason: ") << pError->Getreason () << std::endl;
}
}
}
pDomDocument.Release ();
::CoUninitialize ();
}
return SUCCEEDED (hr) ? EXIT_SUCCESS : EXIT_FAILURE;
}