如何在XPath中使用starts-with()、contains()和ends-with()来查找xml节点innertext?在 XPATH 1.0 中 [英] How to use starts-with() , contains() and ends-with() in XPath to find the xml node innertext? in XPATH 1.0
本文介绍了如何在XPath中使用starts-with()、contains()和ends-with()来查找xml节点innertext?在 XPATH 1.0 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<ArticleBackmatter>
<Heading>Ethical standards and patient consent</Heading>
<Heading>Ethical standards and patient</Heading>
<Heading>standards and patient consent</Heading>
</ArticleBackmatter>
我想在 Heading 节点中获取以 "Ethical" 开头、包含 "and" 并以 "consent" 结尾的内部文本.
I want to get the inner text with start from "Ethical" , contains "and " and end with "consent" in the Heading node.
推荐答案
一种可能的方式:
//Heading[starts-with(., 'Ethical') and ends-with(., 'consent')]
ends-with()
函数是 XPath 2.0.在 XPath 1.0 中,可以使用 substring()
和 string-length 替换
().这是等效的 XPath 1.0(为了可读性而包装):
The ends-with()
function is XPath 2.0. In XPath 1.0, it can be replaced using substring()
and string-length()
. Here is the equivalent XPath 1.0 (wrapped for readability):
//Heading[
starts-with(., 'Ethical')
and
'consent' = substring(., string-length(.) - string-length('consent') +1)
]
这篇关于如何在XPath中使用starts-with()、contains()和ends-with()来查找xml节点innertext?在 XPATH 1.0 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文