查找所有book节点(xpath: //book),对每个节点分析其属性,MSXML都有相关的函数
MSXMLNS::IXMLDOMNodeListPtr pNodeList = NULL;
MSXMLNS::IXMLDOMNamedNodeMapPtr methodpAttrs = NULL;
MSXMLNS::IXMLDOMNodePtr pmethodAttrItem;
MSXMLNS::IXMLDOMNodePtr psNode;
MSXMLNS::IXMLDOMNodePtr requiredNode;
pNodeList = m_pDomDoc->selectNodes((_bstr_t)"//book");
int num = pNodeList->Getlength();
long nCount = 0;
for(int i=0;i<num;i++)
{
psNode=pNodeList->Getitem(i);//取得psNode的节点值
psNode->get_attributes(&methodpAttrs);
methodpAttrs->get_length(&nCount);
for(int nmethod = 0; nmethod < nCount; nmethod++) //属性值的循环
{
methodpAttrs->get_item(nmethod,&pmethodAttrItem);
CString strgetName = FromBSTR((_bstr_t)pmethodAttrItem->nodeName);
CString strgetValue = FromBSTR((_bstr_t)pmethodAttrItem->nodeTypedValue);//得到属性值后进行相应的 *** 作
}
}
$xmlDoc = new DOMDocument;
$xmlDoc -> load($xml_resource);
$xpath = new DOMXPath($xmlDoc);
//$advert_path = '/root/advert[@id="1"]';
$statue_path = '/root/advert/status';
//$advert = $xpath -> query($advert_path) ->item(0);
$replaceNodeOld = $xpath -> query($statue_path) ->item(0);
$replaceNodeNew = = $xmlDoc -> createElement('person', 'fff');//改变成它
$replaceNodeOld = $replaceNodeOld -> item(0)->parentNode->replaceChild($replaceNodeNew, $replaceNodeOld ->item(0));
以上就是关于如何用xpath定位符合多个属性条件的节点集全部的内容,包括:如何用xpath定位符合多个属性条件的节点集、php DOMXPath怎么获取和设置子节点值、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)