void XmlDocumentUnitTests::testGetNodeValue() { struct testGetNodeValue_TestData { LPCWSTR xpath; LPCWSTR result; LPCWSTR xml; }; std::wstring xmlfile = GetLocalFileLocation(L"store.xml"); std::wcout << std::endl << L"Xml: " << xmlfile; AppSecInc::Xml::XmlDocument xml; xml.Load(xmlfile, CLSID_DOMDocument); testGetNodeValue_TestData testdata[] = { { L"/bookstore/book[@id=1]/title", L"'Emma'", L"<title xmlns=\"http://www.lucernepublishing.com\">'Emma'</title>" } }; for (int i = 0; i < ARRAYSIZE(testdata); i++) { // default value std::wstring default_value = xml.GetNodeValue(L"/invalid/xpath", NULL, L"default"); std::wcout << std::endl << L"Value: " << default_value; CPPUNIT_ASSERT(L"default" == default_value); // value std::wstring result_value = xml.GetNodeValue(testdata[i].xpath); std::wcout << std::endl << L"Value: " << result_value; CPPUNIT_ASSERT(testdata[i].result == result_value); // xml std::wstring result_xml = xml.GetNodeXml(testdata[i].xpath); std::wcout << std::endl << L"Xml: " << result_xml; CPPUNIT_ASSERT(testdata[i].xml == result_xml); } }
void XmlDocumentUnitTests::testGetNodeXml() { std::wstring xmlfile = GetLocalFileLocation(L"store.xml"); AppSecInc::Xml::XmlDocument xml; xml.Load(xmlfile, CLSID_DOMDocument); std::wstring data = xml.GetNodeXml(L"/bookstore/book[@id=1]"); CPPUNIT_ASSERT(AppSecInc::StringUtils::startsWith(data, L"<book")); }
CA_API UINT __stdcall Xml_SelectNodeXml(MSIHANDLE hInstall) { MSI_EXCEPTION_HANDLER_PROLOG; MsiInstall msiInstall(hInstall); std::wstring filename = msiInstall.GetProperty(L"XML_FILENAME"); AppSecInc::Xml::XmlDocument doc; doc.Load(filename); std::wstring xpath = msiInstall.GetProperty(L"XML_XPATH"); std::wstring xml = doc.GetNodeXml(xpath); msiInstall.SetProperty(L"XML_NODEXML", xml); MSI_EXCEPTION_HANDLER_EPILOG; return ERROR_SUCCESS; }