本文整理汇总了C++中appsecinc::xml::XmlDocument::SelectNodes方法的典型用法代码示例。如果您正苦于以下问题:C++ XmlDocument::SelectNodes方法的具体用法?C++ XmlDocument::SelectNodes怎么用?C++ XmlDocument::SelectNodes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类appsecinc::xml::XmlDocument
的用法示例。
在下文中一共展示了XmlDocument::SelectNodes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: msiInstall
CA_API UINT __stdcall TemplateFiles_Deferred(MSIHANDLE hInstall)
{
MSI_EXCEPTION_HANDLER_PROLOG;
MsiInstall msiInstall(hInstall);
AppSecInc::Xml::XmlDocument xmlDocument;
xmlDocument.LoadXml(msiInstall.GetActionData());
MSXML2::IXMLDOMNodeListPtr rows = xmlDocument.SelectNodes(L"//TemplateFile[@execute='true']"); // \todo //Row[@rollback='false']
MSXML2::IXMLDOMNodePtr row = NULL;
while (NULL != (row = rows->nextNode()))
{
std::wstring id = xmlDocument.GetAttributeValue(L"id", row);
std::wstring source = xmlDocument.GetNodeValue(L"Source", row);
std::wstring target = xmlDocument.GetNodeValue(L"Target", row, source);
msiInstall.LogInfo(L"TemplateFiles_Deferred", source + L" => " + target);
std::map<std::wstring, std::wstring> properties;
{
MSXML2::IXMLDOMNodeListPtr property_rows = xmlDocument.SelectNodes(L"Properties/Property", row);
MSXML2::IXMLDOMNodePtr property_row = NULL;
while (NULL != (property_row = property_rows->nextNode()))
{
std::wstring name = xmlDocument.GetAttributeValue(L"name", property_row);
std::wstring value = xmlDocument.GetAttributeValue(L"value", property_row);
long escape = AppSecInc::StringUtils::stringToLong(xmlDocument.GetAttributeValue(L"escape", property_row, L"0"));
properties[name] = escape == 1 ? AppSecInc::StringUtils::escape(value) : value;
}
}
std::wstring data;
bool utf8 = AppSecInc::File::ReadAndConvertToEnd(source, data);
data = AppSecInc::Formatter::FormatTemplate(data, properties);
std::string char_data;
if (utf8)
{
char_data = AppSecInc::StringUtils::wc2utf8(data);
char_data.insert(0, std::string(reinterpret_cast<char *>(AppSecInc::File::utf8_bom)));
}
else
{
char_data = AppSecInc::StringUtils::wc2mb(data);
}
std::vector<char> binary_data;
binary_data.assign(char_data.begin(), char_data.end());
AppSecInc::File::FileWrite(target, binary_data);
}
MSI_EXCEPTION_HANDLER_EPILOG;
return ERROR_SUCCESS;
}
示例2: testSelectNodes
void XmlDocumentUnitTests::testSelectNodes()
{
struct testSelectNodes_TestData
{
LPCWSTR xpath;
long count;
};
testSelectNodes_TestData testdata[] =
{
{ L"/bookstore", 1 },
{ L"/bookstore/book", 2 }
};
std::wstring xmlfile = GetLocalFileLocation(L"store.xml");
std::wcout << std::endl << L"Xml: " << xmlfile;
AppSecInc::Xml::XmlDocument xml;
xml.Load(xmlfile, CLSID_DOMDocument);
for (int i = 0; i < ARRAYSIZE(testdata); i++)
{
MSXML2::IXMLDOMNodeListPtr nodes = xml.SelectNodes(testdata[i].xpath);
std::wcout << std::endl << testdata[i].xpath << L": " << nodes->length;
CPPUNIT_ASSERT(testdata[i].count == nodes->length);
}
}
示例3: msiInstall
CA_API UINT __stdcall LocalGroupMembers_Deferred(MSIHANDLE hInstall)
{
MSI_EXCEPTION_HANDLER_PROLOG;
MsiInstall msiInstall(hInstall);
AppSecInc::Xml::XmlDocument xmlDocument;
xmlDocument.LoadXml(msiInstall.GetActionData());
MSXML2::IXMLDOMNodeListPtr rows = xmlDocument.SelectNodes(L"/LocalGroupMembers/LocalGroupMember");
MSXML2::IXMLDOMNodePtr row = NULL;
while (NULL != (row = rows->nextNode()))
{
std::wstring id = xmlDocument.GetAttributeValue(L"id", row);
std::wstring username = xmlDocument.GetNodeValue(L"Username", row);
std::wstring groupname = xmlDocument.GetNodeValue(L"Group", row, L"");
bool add_member = xmlDocument.GetAttributeBoolValue(L"add", row);
bool remove_member = xmlDocument.GetAttributeBoolValue(L"remove", row);
bool check = xmlDocument.GetAttributeBoolValue(L"check", row);
if (remove_member && (! check || AppSecInc::LSA::LocalGroup::IsMember(groupname, username)))
{
msiInstall.LogInfo(_T(__FUNCTION__), L"Removing \"" + username + L"\" from \"" + groupname + L"\"");
AppSecInc::LSA::LocalGroup::DeleteMember(groupname, username);
}
if (add_member && (! check || ! AppSecInc::LSA::LocalGroup::IsMember(groupname, username)))
{
msiInstall.LogInfo(_T(__FUNCTION__), L"Adding \"" + username + L"\" to \"" + groupname + L"\"");
AppSecInc::LSA::LocalGroup::AddMember(groupname, username);
}
}
MSI_EXCEPTION_HANDLER_EPILOG;
return ERROR_SUCCESS;
}
示例4: Test_CreateDatabases_Access
void CreateDatabasesUnitTests::Test_CreateDatabases_Access()
{
AppSecInc::Msi::MsiShim hInstall;
std::wstring testdatapath = AppSecInc::File::GetModuleDirectoryW() + L"\\TestData_DataSourceUnitTests";
for each(const std::wstring& idtfile in AppSecInc::File::GetFiles(testdatapath, L"*.idt"))
{
std::wstring idtfile_name = AppSecInc::File::GetFileNameW(idtfile);
std::wcout << std::endl << L" Importing \"" << idtfile_name << L"\"";
hInstall.Import(testdatapath, idtfile_name);
}
AppSecInc::Msi::MsiInstall msiInstall(hInstall);
std::wstring dbq = AppSecInc::File::DirectoryCombine(
AppSecInc::File::GetTemporaryDirectoryW(),
AppSecInc::Com::GenerateGUIDStringW() + L".dbq");
std::wcout << std::endl << L"DBQ: " << dbq;
msiInstall.SetProperty(L"ACCESS_DATABASE_DBQ", dbq);
msiInstall.SetProperty(L"INSTALLLOCATION", AppSecInc::File::GetSpecialFolderPath(CSIDL_COMMON_APPDATA) + L"\\");
AppSecInc::Xml::XmlDocument xml;
CPPUNIT_ASSERT(ERROR_SUCCESS == hInstall.ExecuteCA(L"DataSource.dll", L"CreateDatabases_Access_Immediate"));
xml.LoadXml(msiInstall.GetProperty(L"CreateDatabases_Access_Deferred_Install"));
// two databases, both have create actions, one is checkIfExists
CPPUNIT_ASSERT(1 == xml.SelectNodes(L"/AccessDatabases/AccessDatabase")->length);
CPPUNIT_ASSERT(1 == xml.SelectNodes(L"/AccessDatabases/AccessDatabase[@actions='create']")->length);
CPPUNIT_ASSERT(1 == xml.SelectNodes(L"/AccessDatabases/AccessDatabase[@checkIfExists='false']")->length);
CPPUNIT_ASSERT(0 == xml.SelectNodes(L"/AccessDatabases/AccessDatabase[@checkIfExists='true']")->length);
// connection strings must be encrypted
MSXML2::IXMLDOMNodeListPtr connectionStrings = xml.SelectNodes(L"/AccessDatabases/AccessDatabase/ConnectionString/text()");
for (int i = 0; i < connectionStrings->length; i++)
{
std::wstring encrypted = StringUtils::mb2wc(StringUtils::bstr2mb(connectionStrings->item[i]->text));
AppSecInc::Crypt::DPAPIImpl::UnProtect(encrypted); // Fails if input string is not encrypted
}
// create the databases
msiInstall.SetProperty(L"CustomActionData", msiInstall.GetProperty(L"CreateDatabases_Access_Deferred_Install"));
CPPUNIT_ASSERT(ERROR_SUCCESS == hInstall.ExecuteCA(L"DataSource.dll", L"CreateDatabases_Access_Deferred"));
// check that the database exists
AppSecInc::Databases::Access::AccessDatabase database;
database.SetDBQ(dbq);
CPPUNIT_ASSERT(database.Exists());
// drop the created databases
MSXML2::IXMLDOMNodePtr Accessdatabase_node;
MSXML2::IXMLDOMNodeListPtr Accessdatabase_nodes = xml.SelectNodes(L"/AccessDatabases/AccessDatabase");
while(NULL != (Accessdatabase_node = Accessdatabase_nodes->nextNode()))
xml.SetAttribute(L"actions", L"drop", Accessdatabase_node);
msiInstall.SetProperty(L"CustomActionData", xml.GetXml());
CPPUNIT_ASSERT(ERROR_SUCCESS == hInstall.ExecuteCA(L"DataSource.dll", L"CreateDatabases_Access_Deferred"));
}
示例5: Test_CreateDatabases_SQLServer
void CreateDatabasesUnitTests::Test_CreateDatabases_SQLServer()
{
AppSecInc::Msi::MsiShim hInstall;
std::wstring testdatapath = AppSecInc::File::GetModuleDirectoryW() + L"\\TestData_DataSourceUnitTests";
for each(const std::wstring& idtfile in AppSecInc::File::GetFiles(testdatapath, L"*.idt"))
{
std::wstring idtfile_name = AppSecInc::File::GetFileNameW(idtfile);
std::wcout << std::endl << L" Importing \"" << idtfile_name << L"\"";
hInstall.Import(testdatapath, idtfile_name);
}
AppSecInc::Msi::MsiInstall msiInstall(hInstall);
std::wstring databasename = AppSecInc::Com::GenerateGUIDStringW();
AppSecInc::StringUtils::lrtrim(databasename, L"{}");
std::wcout << std::endl << L"Database: " << databasename;
msiInstall.SetProperty(L"MSSQL_DATABASE_NAME", databasename);
msiInstall.SetProperty(L"INSTALLLOCATION", AppSecInc::File::GetSpecialFolderPath(CSIDL_COMMON_APPDATA) + L"\\");
AppSecInc::Xml::XmlDocument xml;
CPPUNIT_ASSERT(ERROR_SUCCESS == hInstall.ExecuteCA(L"DataSource.dll", L"CreateDatabases_SQLServer_Immediate"));
xml.LoadXml(msiInstall.GetProperty(L"CreateDatabases_SQLServer_Deferred_Install"));
// two databases, both have create actions, one is checkIfExists
CPPUNIT_ASSERT(2 == xml.SelectNodes(L"/MSSQLDatabases/MSSQLDatabase")->length);
CPPUNIT_ASSERT(2 == xml.SelectNodes(L"/MSSQLDatabases/MSSQLDatabase[@actions='create']")->length);
CPPUNIT_ASSERT(1 == xml.SelectNodes(L"/MSSQLDatabases/MSSQLDatabase[@checkIfExists='false']")->length);
CPPUNIT_ASSERT(1 == xml.SelectNodes(L"/MSSQLDatabases/MSSQLDatabase[@checkIfExists='true']")->length);
// only the first database has options, but each have two file specs
CPPUNIT_ASSERT(1 == xml.SelectNodes(L"/MSSQLDatabases/MSSQLDatabase/MSSQLDatabaseOptions/MSSQLDatabaseOption")->length);
CPPUNIT_ASSERT(4 == xml.SelectNodes(L"/MSSQLDatabases/MSSQLDatabase/MSSQLDatabaseFileSpecs/MSSQLDatabaseFileSpec")->length);
// connection strings must be encrypted
MSXML2::IXMLDOMNodeListPtr connectionStrings = xml.SelectNodes(L"/MSSQLDatabases/MSSQLDatabase/ConnectionString/text()");
for (int i = 0; i < connectionStrings->length; i++)
{
std::wstring encrypted = StringUtils::mb2wc(StringUtils::bstr2mb(connectionStrings->item[i]->text));
AppSecInc::Crypt::DPAPIImpl::UnProtect(encrypted); // Fails if input string is not encrypted
}
// create the databases
msiInstall.SetProperty(L"CustomActionData", msiInstall.GetProperty(L"CreateDatabases_SQLServer_Deferred_Install"));
CPPUNIT_ASSERT(ERROR_SUCCESS == hInstall.ExecuteCA(L"DataSource.dll", L"CreateDatabases_SQLServer_Deferred"));
// check that both databases exist
AppSecInc::Databases::MSSQL::MSSQLConnectionInfo connection_info;
connection_info.SetIPAddress(L"localhost");
AppSecInc::Databases::MSSQL::MSSQLDatabase database(connection_info);
database.Connect();
// check the first database
database.SetName(databasename);
CPPUNIT_ASSERT(database.Exists());
// check the second database
database.SetName(databasename + L"2");
CPPUNIT_ASSERT(database.Exists());
// drop the created databases
MSXML2::IXMLDOMNodePtr mssqldatabase_node;
MSXML2::IXMLDOMNodeListPtr mssqldatabase_nodes = xml.SelectNodes(L"/MSSQLDatabases/MSSQLDatabase");
while(NULL != (mssqldatabase_node = mssqldatabase_nodes->nextNode()))
xml.SetAttribute(L"actions", L"drop", mssqldatabase_node);
msiInstall.SetProperty(L"CustomActionData", xml.GetXml());
CPPUNIT_ASSERT(ERROR_SUCCESS == hInstall.ExecuteCA(L"DataSource.dll", L"CreateDatabases_SQLServer_Deferred"));
}