【问题标题】:Difficult XPath with more conditions具有更多条件的困难 XPath
【发布时间】:2016-04-25 11:45:17
【问题描述】:
 <devices>
    <deviceType>PHONE</deviceType>
    <account>717</accountId>
    <attributes>
      <value>New PHONE 1</value>
      <key>FRIENDLY_NAME</key>
    </attributes>
    <attributes>
      <value>TRUE</value>
      <key>DOWNLOAD </key>
    </attributes>
    <attributes>
      <value>1454737</value>
      <key> TIMESTAMP</key>
    </attributes>
    <deviceId>550BDC49DA724C</deviceId>
  </devices>
  <devices>
    <deviceType>WEB</deviceType>
    <accountId>717</accountId>
    <attributes>
      <value>2016-04-11 08:53:52.866;</value>
      <key>REGISTRATION </key>
    </attributes>
    <attributes>
      <value>TRUE</value>
      <key>ACTIVE_DEVICE</key>
    </attributes>
    <creationDate>146036872</creationDate>
    <deviceId>997C6AADB51</deviceId>
  </devices>

我需要获取 deviceId WHERE deviceType=PHONE、TABLET 或 WEB 的值,并且此设备具有 key=DOWNLOAD 和 value=TRUE 的属性。感谢您提供正确的 XPath。

【问题讨论】:

    标签: xml xpath multiple-conditions


    【解决方案1】:

    “我需要获取 deviceId WHERE deviceType=PHONE、TABLET 或 WEB 的值,并且此设备具有 key=DOWNLOAD 和 value=TRUE 的属性”

    这是一种可能的方式:

    //devices[deviceType='PHONE' or deviceType='TABLET' or deviceType='WEB']
             [attributes[key='DOWNLOAD' and value='TRUE']]
     /deviceId
    

    演示:xpathtesterxpatheval

    【讨论】:

    • 致 OP:如果您的实际 XML 中 key 的值可能包含额外的空格,请使用 normalize-space(key)
    • @Michal 你说的另一种方式是什么意思?你需要什么样的方式?
    猜你喜欢
    • 2012-05-02
    • 2010-11-29
    • 1970-01-01
    • 1970-01-01
    • 2022-01-03
    • 2015-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多