有更多条件的困难XPath

时间:2016-04-25 11:45:18

标签: xml xpath multiple-conditions

 <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。

1 个答案:

答案 0 :(得分:0)

  

“我需要获取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