xml - XML标记的XPath取决于文本中的位置?
问题描述
我正在寻找能够区分涉及相同标签的两个场景的 XPath 表达式。
场景 1:
<include.text>
出现在字符串的中间,例如:
<par>We are certain that <include.text><Reference/></include.text> will be a big hit.</par>
场景 2:
<include.text>
直接出现在另一个(任意)标签之后,例如:
<par><include.text><Reference/></include.text> will be a big hit.</par>
就我而言,我可以//include.text
用于第一个场景,但我需要另一个 Xpath 表达式,它允许我区分它直接出现在开始标签之后的场景(par
在这种情况下,它可以是任何东西)。通常,开始标签 ( par
) 将是父级而不是兄弟级。我已经研究过ends-with()
,等等,但我还不太擅长 XPath。
解决方案
对于这个 XML,
<r>
<par>We are certain that <include.text><Reference/></include.text> will be a big hit.</par>
<par><include.text><Reference/></include.text> will be a big hit.</par>
</r>
这个 XPath,
//include.text[not(preceding-sibling::node())]
将只选择第二个include.text
,因为它没有前面的兄弟节点。
推荐阅读
- django - 如何在 django 中指定多对一模型?
- reactjs - 如何在地图功能中的 onclick 上切换类?
- java - 将 POJO 对象放入 JTable
- java - 异常发送警报:java.net.SocketException: Broken pipe (Write failed)
- apache-spark - 尽管有资源,但 Spark Jobs 处于 ACCEPTED 状态
- javascript - 比较数组时出现 Chai 断言错误
- android - 上传的 APK 没有有效的签名 Firebase TestLab 仪器测试类型
- ios - 如何将内容从一个应用程序共享到另一个应用程序
- r - 从折叠字符中提取正则表达式(包括“|”)
- rest-assured - 如何从响应中验证类型?