I am trying to read some XML code from a website, and am having a bit of trouble figuring out where my errors are. Using the code from this extremely useful post, I am trying to read a file that I have saved to my desktop ("H:\MyName\Desktop\secLendingXML.cfm.xml"). The code is below:
#include "stdafx.h"
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#import <msxml6.dll> rename_namespace(_T("MSXML"))
int main(/*int argc, char* argv[]*/)
{
HRESULT hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
try
{
MSXML::IXMLDOMDocument2Ptr xmlDoc;
hr = xmlDoc.CreateInstance(__uuidof(MSXML::DOMDocument60), NULL, CLSCTX_INPROC_SERVER);
// TODO: if (FAILED(hr))...
if (xmlDoc->load(_T("H:\MyName\Desktop\secLendingXML.cfm.xml")) != VARIANT_TRUE)
{
printf("Unable to load input.xml\n");
}
else
{
printf("XML was successfully loaded\n");
xmlDoc->setProperty("SelectionLanguage", "XPath");
MSXML::IXMLDOMNodeListPtr wheels = xmlDoc->selectNodes("/Car/Wheels/*");
printf("Car has %u wheels\n", wheels->Getlength());
MSXML::IXMLDOMNodePtr node;
node = xmlDoc->createNode(MSXML::NODE_ELEMENT, _T("Engine"), _T(""));
node->text = _T("Engine 1.0");
xmlDoc->documentElement->appendChild(node);
hr = xmlDoc->save(_T("output.xml"));
if (SUCCEEDED(hr))
printf("output.xml successfully saved\n");
}
}
catch (_com_error &e)
{
printf("ERROR: %ws\n", e.ErrorMessage());
}
CoUninitialize();
}
system("PAUSE");
return 0;
}
The message "Unable to load input.xml" always shows, so I know I'm not having an error, but that the code is unable to load my XML file.
Do I need to save the XML file in a different location? Is the ".cfm" before the ".xml" screwing with the reading process?
To give an idea of my intended direction, I want to be able to load the XML file from the New York Fed website and read it into some sort of data file where I can automate the data retrieving process. That way, whenever the website is updated, I will automatically be notified, and it will be reflected by the change in the data file that I will have saved somewhere on my computer. If anyone also wants to help with how I go about that part - poll intervals, tracking website changes, etc. - that would also be appreciated.
Thank you for any and all help.