I have this XML file below:
<catalog>
<book id="bk101">
<author> Gambardella, Matthew </author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications with XML.</description>
</book>
</catalog>
I would like to print the attribute inside the book
node (that being the value of id
, which is bk101
), however I'm having trouble using the MSXML6 library to do so, and I would like to stick with it instead of changing to Rapid, etc.
Below is my code so far:
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#import <msxml6.dll> rename_namespace(_T("MSXML"))
#include<iostream>
#include<string>
int main(int argc, char* argv[]) {
HRESULT hr = CoInitialize(NULL);
if (SUCCEEDED(hr)) {
try {
MSXML::IXMLDOMDocument2Ptr xmlDoc;
MSXML::IXMLDOMNodePtr bookholder;
MSXML::IXMLDOMNodePtr author;
MSXML::IXMLDOMNodePtr title;
hr = xmlDoc.CreateInstance(__uuidof(MSXML::DOMDocument60),
NULL, CLSCTX_INPROC_SERVER);
// TODO: if (FAILED(hr))...
if (xmlDoc->load(_T("books.xml")) != VARIANT_TRUE) {
printf("Unable to load input.xml\n");
}
else {
printf("XML was successfully loaded\n");
xmlDoc->setProperty("SelectionLanguage", "XPath");
MSXML::IXMLDOMNodeListPtr booklist = xmlDoc->selectNodes("/catalog/*");
bookholder = booklist->Getitem(0);
//printf(bookholder->Getxml()+"\n"); //works till here
//printf(bookholder->; //what to do here to print attribute?
}
}
catch (_com_error& e) {
printf("ERROR: %ws\n", e.ErrorMessage());
}
CoUninitialize();
}
return 0;
}