Пример #1
0
void XmlDocumentUnitTests::testFindNodes() 
{ 
	std::wstring xmlfile = GetLocalFileLocation(L"store.xml");
	AppSecInc::Xml::XmlDocument xml;
	xml.Load(xmlfile, CLSID_DOMDocument);
	CPPUNIT_ASSERT(NULL != xml.FindNodes(L"/bookstore/book[@id=1]"));
	CPPUNIT_ASSERT(NULL == xml.FindNodes(L"/bookstore/book[@id=1]/invalid/"));
}
Пример #2
0
CA_API UINT __stdcall Xml_DeleteNodes(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");
    MSXML2::IXMLDOMNodeListPtr nodes = doc.FindNodes(xpath);
    int count = 0;
    if (NULL != nodes)
    {
        MSXML2::IXMLDOMNodePtr node = NULL;
        while (NULL != (node = nodes->nextNode()))
        {
            node->parentNode->removeChild(node);
            count++;
        }
    }

    if (count > 0)
    {
        CHECK_HR(doc->save(CComVariant(filename.c_str())),
                 L"Error saving '" << filename << L"'");
    }

    msiInstall.SetProperty(L"XML_DELETED", AppSecInc::StringUtils::toWString(count));
    MSI_EXCEPTION_HANDLER_EPILOG;
    return ERROR_SUCCESS;
}