Mr. Rattles
August 21st, 2000, 10:04 PM
The following test program I'm trying to create to get acquainted with the XML SDK is failing on the attempt to create the instance of the Document. Here's the code:
#include "stdafx.h"
#include <stdio.h>
#include <comdef.h>
#include <msxml.h>
#include <atlbase.h>
#define CHECKHR(hr, error) { if (FAILED(hr)) { printf("%s\n", error); return 1; } }
int main()
{
CComPtr spDoc;
CComPtr spEle;
CComBSTR bsStr("NAME");
CComVariant vVal((int)NODE_ELEMENT);
HRESULT hr;
hr = spDoc.CoCreateInstance(__uuidof(DOMDocument));
CHECKHR(hr, "Error creating document");
hr = spDoc->createElement(bsStr, &spEle);
CHECKHR(hr, "Error creating element");
bsStr = "first";
vVal = "John";
hr = spEle->setAttribute(bsStr, vVal);
CHECKHR(hr, "Error setting first name attribute");
bsStr = "last";
vVal = "Smith";
hr = spEle->setAttribute(bsStr, vVal);
CHECKHR(hr, "Error setting last name attribute");
hr = spDoc->putref_documentElement(spEle);
CHECKHR(hr, "Error setting document element");
vVal = ".\text.xml";
hr = spDoc->save(vVal);
CHECKHR(hr, "Error saving XML document");
spDoc.Release();
return 0;
}
Any suggestions on why it's failing? It's not any of the three defined errors in the Platform SDK.
Thanks for the help
#include "stdafx.h"
#include <stdio.h>
#include <comdef.h>
#include <msxml.h>
#include <atlbase.h>
#define CHECKHR(hr, error) { if (FAILED(hr)) { printf("%s\n", error); return 1; } }
int main()
{
CComPtr spDoc;
CComPtr spEle;
CComBSTR bsStr("NAME");
CComVariant vVal((int)NODE_ELEMENT);
HRESULT hr;
hr = spDoc.CoCreateInstance(__uuidof(DOMDocument));
CHECKHR(hr, "Error creating document");
hr = spDoc->createElement(bsStr, &spEle);
CHECKHR(hr, "Error creating element");
bsStr = "first";
vVal = "John";
hr = spEle->setAttribute(bsStr, vVal);
CHECKHR(hr, "Error setting first name attribute");
bsStr = "last";
vVal = "Smith";
hr = spEle->setAttribute(bsStr, vVal);
CHECKHR(hr, "Error setting last name attribute");
hr = spDoc->putref_documentElement(spEle);
CHECKHR(hr, "Error setting document element");
vVal = ".\text.xml";
hr = spDoc->save(vVal);
CHECKHR(hr, "Error saving XML document");
spDoc.Release();
return 0;
}
Any suggestions on why it's failing? It's not any of the three defined errors in the Platform SDK.
Thanks for the help