gpt4 book ai didi

xml - XPath 匹配通配符?

转载 作者:数据小太阳 更新时间:2023-10-29 02:28:43 27 4
gpt4 key购买 nike

希望在属性为路径的 xpath 中使用通配符,我希望所有路径都以“文本”结尾。

示例:<Property name="jcr:content/MainParsys/*/text"/>

  • jcr:content/MainParsys是常数。
  • *是我想要通配符的地方(中间的所有路径)。
  • text是我正在寻找的路径的最后一部分。

此外,还有以/textIsRich结尾的路径我想避免。

寻找: <Property name="jcr:content/MainParsys/*/text"/>

避免:<Property name="jcr:content/MainParsys/*/text *"/>

最佳答案

XPath 1.0

这个 XPath,

//Property[@name[  starts-with(.,'jcr:content/MainParsys/')
and substring(., string-length(.) - string-length('/text') +1) = '/text']]

将选择所有具有 name 属性的 Property 元素,该属性的值以 'jcr:content/MainParsys/' 开头并以 结尾>'/text'(使用标准 XPath 1.0 work-around for no ends-with() function )。

XPath 2.0

XPath 2.0 具有 ends-with() 以及正则表达式函数,例如 matches()例如,可以匹配有效的通配符 (.*)。

关于xml - XPath 匹配通配符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47422305/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com