Last active
August 26, 2018 20:19
-
-
Save maldevel/a7110466602beb646cd605d61263e99b to your computer and use it in GitHub Desktop.
PassCat Reading XML snippet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://github.com/twelvesec/passcat | |
//GNU General Public License v3.0 | |
//@maldevel | |
#include <string> | |
#include <tchar.h> | |
#import <msxml6.dll>rename_namespace(_T("MSXML")) | |
//... | |
void libxml::init(void) { | |
CoInitialize(NULL); | |
initialized = true; | |
} | |
void libxml::finalize(void) { | |
if (!initialized) return; | |
CoUninitialize(); | |
initialized = false; | |
} | |
MSXML::IXMLDOMNodeListPtr libxml::select_by_path(std::wstring filename, std::wstring XPATH) { | |
if (!initialized) return NULL; | |
MSXML::IXMLDOMDocument2Ptr xmlDoc; | |
try { | |
HRESULT hr = xmlDoc.CreateInstance(__uuidof(MSXML::DOMDocument60)); | |
if (FAILED(hr)) { | |
return NULL; | |
} | |
if (xmlDoc->load(_variant_t(filename.c_str())) != VARIANT_TRUE) { | |
std::wcout << "Unable to load " << filename << std::endl; | |
} | |
else { | |
return xmlDoc->selectNodes(_bstr_t(XPATH.c_str())); | |
} | |
} | |
catch (_com_error &e) { | |
std::cout << e.ErrorMessage() << std::endl; | |
xmlDoc = NULL; | |
} | |
return NULL; | |
} | |
//... | |
/////////////////////////////////////////////////////////////////////////////////////// | |
#include "libxml.h" | |
libpasscat::init(); | |
MSXML::IXMLDOMNodeListPtr list = libxml::select_by_path(filename, XPATH); | |
for (long i = 0; i != list->length; ++i) { | |
//... | |
std::wcout << "Host: " << list->item[i]->selectSingleNode("Host")->text << std::endl; | |
//... | |
} | |
libpasscat::finalize(); | |
//... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment