本文介绍了通过内文选择 XPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从已解析的 XML 文档中提取具有特定内部文本的元素.我知道我可以使用 //myparent[mychild='foo']
选择一个具有特定内部文本的子元素,但实际上我只想在此示例中选择mychild"元素.
I'm trying to extract an element with a particular innertext from a parsed XML document. I know that I can select an element that has a child with a particular innertext using //myparent[mychild='foo']
, but I actually just want to select the "mychild" element in this example.
<myparent>
<mychild>
foo
</mychild>
</myparent>
返回mychild"节点的foo"的 XPath 查询是什么?
What would be the XPath query for "foo" that would return the "mychild" node?
推荐答案
你试过了吗?
//myparent/mychild[text() = 'foo']
或者,您可以使用 self
轴的快捷方式:
Alternatively, you can use the shortcut for the self
axis:
//myparent/mychild[. = 'foo']
这篇关于通过内文选择 XPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!