本文整理汇总了C++中appsecinc::xml::XmlDocument::Load方法的典型用法代码示例。如果您正苦于以下问题:C++ XmlDocument::Load方法的具体用法?C++ XmlDocument::Load怎么用?C++ XmlDocument::Load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类appsecinc::xml::XmlDocument
的用法示例。
在下文中一共展示了XmlDocument::Load方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testGetNodeValue
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);
}
}
示例2: testGetNodeBoolValue
void XmlDocumentUnitTests::testGetNodeBoolValue()
{
struct testGetNodeBoolValue_TestData
{
LPCWSTR xpath;
bool result;
};
std::wstring xmlfile = GetLocalFileLocation(L"store.xml");
std::wcout << std::endl << L"Xml: " << xmlfile.c_str();
AppSecInc::Xml::XmlDocument xml;
xml.Load(xmlfile, CLSID_DOMDocument);
testGetNodeBoolValue_TestData testdata[] =
{
{ L"/bookstore/book[@id=1]/read", false },
{ L"/bookstore/book[@id=2]/read", true },
};
for (int i = 0; i < ARRAYSIZE(testdata); i++)
{
// value
bool result_value = xml.GetNodeBoolValue(testdata[i].xpath);
std::wcout << std::endl << L"Value: " << result_value;
CPPUNIT_ASSERT(testdata[i].result == result_value);
}
}
示例3: 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);
}
}
示例4: testGetAttributeValueXPath
void XmlDocumentUnitTests::testGetAttributeValueXPath()
{
struct testGetAttributeValue_TestData
{
LPCWSTR xpath;
LPCWSTR name;
LPCWSTR result;
};
std::wstring xmlfile = GetLocalFileLocation(L"store.xml");
std::wcout << std::endl << L"Xml: " << xmlfile;
AppSecInc::Xml::XmlDocument xml;
xml.Load(xmlfile, CLSID_DOMDocument);
testGetAttributeValue_TestData testdata[] =
{
{ L"/bookstore/book[@id=1]", L"id", L"1" }
};
for (int i = 0; i < ARRAYSIZE(testdata); i++)
{
MSXML2::IXMLDOMNodePtr node = xml.SelectNode(testdata[i].xpath);
// default value
std::wstring default_value = xml.GetAttributeValue(L"invalid", node, L"default");
std::wcout << std::endl << L"Value: " << default_value;
CPPUNIT_ASSERT(L"default" == default_value);
// value
std::wstring result_value = xml.GetAttributeValue(testdata[i].name, node);
std::wcout << std::endl << L"Value: " << result_value;
CPPUNIT_ASSERT(testdata[i].result == result_value);
}
}
示例5: msiInstall
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;
}
示例6: testHasAttribute
void XmlDocumentUnitTests::testHasAttribute()
{
std::wstring xmlfile = GetLocalFileLocation(L"store.xml");
AppSecInc::Xml::XmlDocument xml;
xml.Load(xmlfile, CLSID_DOMDocument);
CPPUNIT_ASSERT(xml.HasAttribute(L"id", xml.SelectNode(L"/bookstore/book[@id=1]")));
CPPUNIT_ASSERT(! xml.HasAttribute(L"iddoesntexist", xml.SelectNode(L"/bookstore/book[@id=1]")));
}
示例7: testGetNodeXml
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"));
}
示例8: testFindNodes
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/"));
}
示例9: testHasNode
void XmlDocumentUnitTests::testHasNode()
{
std::wstring xmlfile = GetLocalFileLocation(L"store.xml");
AppSecInc::Xml::XmlDocument xml;
xml.Load(xmlfile, CLSID_DOMDocument);
CPPUNIT_ASSERT(xml.HasNode(L"/bookstore/book[@id=1]/title"));
CPPUNIT_ASSERT(! xml.HasNode(L"/bookstore/book[@id=1]/invalid"));
}
示例10: testLoad
void XmlDocumentUnitTests::testLoad()
{
std::wstring xmlfile = GetLocalFileLocation(L"store.xml");
std::wcout << std::endl << L"Xml: " << xmlfile.c_str();
AppSecInc::Xml::XmlDocument xml;
xml.Load(xmlfile, CLSID_DOMDocument);
CPPUNIT_ASSERT(AppSecInc::StringUtils::startsWith(xml.GetXml(),
L"<bookstore xmlns=\"http://www.lucernepublishing.com\">"));
}
示例11: testGetXml
void XmlDocumentUnitTests::testGetXml()
{
std::wstring xmlfile = GetLocalFileLocation(L"store.xml");
std::wcout << std::endl << L"Xml: " << xmlfile;
AppSecInc::Xml::XmlDocument xml;
xml.Load(xmlfile);
std::wstring outerxml = xml.GetXml();
CPPUNIT_ASSERT(! outerxml.empty());
//! \todo read the file with File::ReadToEnd (implement) and compare data
}
示例12: testGetAttributeValue
void XmlDocumentUnitTests::testGetAttributeValue()
{
std::wstring xmlfile = GetLocalFileLocation(L"store.xml");
std::wcout << std::endl << L"Xml: " << xmlfile;
AppSecInc::Xml::XmlDocument xml;
xml.Load(xmlfile);
std::wstring result = xml.GetAttributeValue(L"/bookstore/book", L"id");
std::wcout << std::endl << L"Value: " << result;
CPPUNIT_ASSERT(result == L"1");
}
示例13: testSelectAttribute
void XmlDocumentUnitTests::testSelectAttribute()
{
std::wstring xmlfile = GetLocalFileLocation(L"store.xml");
AppSecInc::Xml::XmlDocument xml;
xml.Load(xmlfile, CLSID_DOMDocument);
CPPUNIT_ASSERT(NULL != xml.SelectAttribute(L"id", xml.SelectNode(L"/bookstore/book[@id=1]")));
try
{
xml.SelectAttribute(L"iddoesntexist", xml.SelectNode(L"/bookstore/book[@id=1]"));
throw "expected std::exception";
}
catch(std::exception& e)
{
std::cout << std::endl << "Expected exception: " << e.what();
}
}
示例14: testXslTransform
void XmlDocumentUnitTests::testXslTransform()
{
// check test xml file
std::wstring xmlfile = GetLocalFileLocation(L"simple.xml");
std::wcout << std::endl << L"Xml: " << xmlfile;
CPPUNIT_ASSERT(File::FileExists(xmlfile));
// check test xsl file
std::wstring xslfile = GetLocalFileLocation(L"simple.xsl");
std::wcout << std::endl << L"Xsl: " << xslfile;
CPPUNIT_ASSERT(File::FileExists(xslfile));
// transform
AppSecInc::Xml::XmlDocument xml;
xml.Load(xmlfile);
AppSecInc::Xml::XmlDocument transformedXml;
std::wstring transformResult = xml.XslTransform(xslfile);
transformedXml.LoadXml(transformResult);
// load the result
CPPUNIT_ASSERT(transformResult.length() > 0);
}