开发者

msxml selectnodes: namespace in text node

I have to following XML file:

<root xmlns="http://someurl/element" xmlns:text="http://someurl/text">
   <elements>
     <element>
       <Id>text:SOME_ID</Id>
       <!-- some other elements -->
     </element>
     <element>
       <!-- some other elements -->
       <reference>
          <link ref="text:SOME_ID" />
       </refernce>
     </element>
   </elements>
</root>

I want to select all child elements of the elment node which have the element Id=text:SOME_ID from the reference node. I want to do this in C++ by using the selectNodes method of the IXMLDOMNode object from msxml parser.

In the following exmaple I have the refence node selected in pC开发者_Python百科hild and the SelectionNamespaces propetey set to xmlns:n="http://someurl/element":

MSXML2::IXMLDOMNodePtr pSelectedNodes =
    pChild->selectNodes("../../n:element[n:Id=n:link/@ref]/n:*");
__ASSERT(pSelectedNodes->length > 0)

This is not working. What am I doing wrong?


The n:link/@ref part of your XPath query is evaluated in the context of the element to which the conditional criteria are applied; in this case the ../../n:element.
You can’t reference the overall context from within a conditional section; in other words, the context node is different inside and outside of the [square brackets].

I’m afraid you will have to extract the pChild->selectSingleNode("n:link/@ref")->text separately, and 'manually' insert that into your XPath query.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜