Skip to content

Instantly share code, notes, and snippets.

@vSzemkel
Last active August 31, 2017 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vSzemkel/d49792e1d073a2f087dfc8e8caa5ebc8 to your computer and use it in GitHub Desktop.
Save vSzemkel/d49792e1d073a2f087dfc8e8caa5ebc8 to your computer and use it in GitHub Desktop.
Download, parse and read IXMLDOMDocument
#include <afx.h>
#include <msxml2.h>
HRESULT CDocumentEvidenceManager::TryResolvePageDerivation(SDocumentEvidence evidence, const char* destinationPath)
{
HRESULT ret = S_OK;
// format url with xml source stream
CString url;
const CString title = evidence.szTitle;
url.Format("http://*****.*****.pl/WsSpac/Strony?tyt=%s&mut=%s&kiedy=20%s", title.Left(3), title.Mid(3), evidence.szPubDate);
// open stream
CComPtr<IStream> stream;
ret = ::URLOpenBlockingStream(nullptr, url, &stream, 0, nullptr);
if (ret != S_OK) return ret;
// create document
CComPtr<IXMLDOMDocument> m_spDom;
ret = m_spDom.CoCreateInstance(__uuidof(DOMDocument2));
if (ret != S_OK) return ret;
// load document
VARIANT_BOOL retval = VARIANT_TRUE;
CComVariant varXML(stream);
ret = m_spDom->load(varXML, &retval);
if (ret != S_OK) return ret;
// execute XPath query
CStringW path;
path.Format(L"//strona[@lp=%i]/dziedziczona", evidence.nPageNo);
IXMLDOMNode* node;
ret = m_spDom->selectSingleNode((BSTR)(const wchar_t*)path, &node);
if (ret != S_OK) return ret;
// read result
BSTR bs;
node->get_text(&bs);
path = bs;
/* not relevant code here */
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment