【问题标题】:How to use XPath to filter elements by the value of another property?如何使用 XPath 通过另一个属性的值过滤元素?
【发布时间】:2019-07-11 14:56:32
【问题描述】:

我有这个

    XPathExpression expr = xpath.compile("/job/entries/entry/name/text()");

我需要按 type 属性的文本值进行过滤,因此我只获取 type 中具有 JOB 值的条目对象。

<job>
 <entries>
    <entry>
      <name>OperationalDataStoreToReconciled</name>
      <description/>
      <type>JOB</type>
    </entry>
 </entries>
</job>

【问题讨论】:

标签: java xml xpath


【解决方案1】:

使用下面的 xpath。

 //job/entries/entry[./type[.='JOB']]

截图:

【讨论】:

    猜你喜欢
    • 2022-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-11
    • 1970-01-01
    • 1970-01-01
    • 2012-08-28
    相关资源
    最近更新 更多