XPath:如何选择节点的第一个给定父节点?

Zan*_*oni 2 c# xml xpath

我的XML:

<root>
  <child>
     <childOfChild>
        <anotherLostChild>
           <currentSelectedNode>
              SOME TEXT
           </currentSelectedNode>
        </anotherLostChild>
     </childOfChild>
  </child>
</root>
Run Code Online (Sandbox Code Playgroud)

我使用以下方法选择了节点currentSelectedNode:

xpath.SelectSingleNode("//currentSelectedNode")
Run Code Online (Sandbox Code Playgroud)

但是,如何返回选择第一个chilfOfChild父节点(考虑到上下文是currentSelectedNode

xpath.SelectSingleNode("//currentSelectedNode")...???
Run Code Online (Sandbox Code Playgroud)

ann*_*ata 13

你的问题真的很混乱,但听起来你想要祖先的轴,比如:

//currentSelectedNode/ancestor::childOfChild[1]
Run Code Online (Sandbox Code Playgroud)

(纯xpath解决方案)