本文整理汇总了C++中IXMLDOMDocument::selectNodes方法的典型用法代码示例。如果您正苦于以下问题:C++ IXMLDOMDocument::selectNodes方法的具体用法?C++ IXMLDOMDocument::selectNodes怎么用?C++ IXMLDOMDocument::selectNodes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IXMLDOMDocument
的用法示例。
在下文中一共展示了IXMLDOMDocument::selectNodes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getOrderedDcmFiles
QStringList DicomImageSet::getOrderedDcmFiles(const QString &datasetFileName, const QString & queryString)
{
HRESULT hr = S_OK;
IXMLDOMDocument *pXMLDom = NULL;
IXMLDOMNodeList *pFileNodes = NULL;
VARIANT_BOOL varStatus;
VARIANT varFileName;
BSTR bstrQuery;
QStringList fileList;
CHK_HR(CreateAndInitDOM(&pXMLDom));
CHK_HR(VariantFromString(datasetFileName.toStdWString().c_str(), varFileName));
CHK_HR(pXMLDom->load(varFileName, &varStatus));
if (varStatus != VARIANT_TRUE)
{
CHK_HR(ReportParseError(pXMLDom, "Failed to load DOM from stocks.xml."));
}
bstrQuery = SysAllocString(queryString.toStdWString().c_str());
CHK_ALLOC(bstrQuery);
CHK_HR(pXMLDom->selectNodes(bstrQuery, &pFileNodes));
if (pFileNodes)
{
long nFiles;
CHK_HR(pFileNodes->get_length(&nFiles));
for (long i=0; i<nFiles; ++i)
{
VARIANT varValue;
IXMLDOMNode * pFile = NULL;
CHK_HR(pFileNodes->get_item(i, &pFile));
CHK_HR(GetAttributeFromNode(pFile, L"path", &varValue));
fileList <<QString::fromWCharArray(_bstr_t(varValue));
SAFE_RELEASE(pFile);
}
}
CleanUp:
SAFE_RELEASE(pXMLDom);
SAFE_RELEASE(pFileNodes);
return fileList;
}
示例2: queryNodes
void queryNodes()
{
HRESULT hr = S_OK;
IXMLDOMDocument *pXMLDom = NULL;
IXMLDOMNodeList *pNodes = NULL;
IXMLDOMNode *pNode = NULL;
BSTR bstrQuery1 = NULL;
BSTR bstrQuery2 = NULL;
BSTR bstrNodeName = NULL;
BSTR bstrNodeValue = NULL;
VARIANT_BOOL varStatus;
VARIANT varFileName;
VariantInit(&varFileName);
CHK_HR(CreateAndInitDOM(&pXMLDom));
CHK_HR(VariantFromString(L"stocks.xml", varFileName));
CHK_HR(pXMLDom->load(varFileName, &varStatus));
if (varStatus != VARIANT_TRUE)
{
CHK_HR(ReportParseError(pXMLDom, "Failed to load DOM from stocks.xml."));
}
// Query a single node.
bstrQuery1 = SysAllocString(L"//stock[1]/*");
CHK_ALLOC(bstrQuery1);
CHK_HR(pXMLDom->selectSingleNode(bstrQuery1, &pNode));
if (pNode)
{
printf("Result from selectSingleNode:\n");
CHK_HR(pNode->get_nodeName(&bstrNodeName));
printf("Node, <%S>:\n", bstrNodeName);
SysFreeString(bstrNodeName);
CHK_HR(pNode->get_xml(&bstrNodeValue));
printf("\t%S\n\n", bstrNodeValue);
SysFreeString(bstrNodeValue);
SAFE_RELEASE(pNode);
}
else
{
CHK_HR(ReportParseError(pXMLDom, "Error while calling selectSingleNode."));
}
// Query a node-set.
bstrQuery2 = SysAllocString(L"//stock[1]/*");
CHK_ALLOC(bstrQuery2);
CHK_HR(pXMLDom->selectNodes(bstrQuery2, &pNodes));
if(pNodes)
{
printf("Results from selectNodes:\n");
//get the length of node-set
long length;
CHK_HR(pNodes->get_length(&length));
for (long i = 0; i < length; i++)
{
CHK_HR(pNodes->get_item(i, &pNode));
CHK_HR(pNode->get_nodeName(&bstrNodeName));
/*if(0== wcscmp(bstrNodeValue, L"symbol"))
{
}
*/
printf("Node (%d), <%S>:\n", i, bstrNodeName);
SysFreeString(bstrNodeName);
CHK_HR(pNode->get_xml(&bstrNodeValue));
printf("\t%S\n", bstrNodeValue);
SysFreeString(bstrNodeValue);
SAFE_RELEASE(pNode);
}
}
else
{
CHK_HR(ReportParseError(pXMLDom, "Error while calling selectNodes."));
}
CleanUp:
SAFE_RELEASE(pXMLDom);
SAFE_RELEASE(pNodes);
SAFE_RELEASE(pNode);
SysFreeString(bstrQuery1);
SysFreeString(bstrQuery2);
SysFreeString(bstrNodeName);
SysFreeString(bstrNodeValue);
VariantClear(&varFileName);
}