Xpath计数功能不起作用

时间:2016-01-27 13:44:10

标签: xml xpath count

我有以下Xml文档:

 <root>
<lockerEntries>
    <accountId>
      <accountId>717</accountId>
      <businessUnit>USIT</businessUnit>
    </accountId>
    <policyId>ps_d8d</policyId>
    <id>0X02A9C2A2E59145DAFF482</id>
    <lastModified>1448265403925</lastModified>
    <authorizationStart>1448265403453</authorizationStart>
    <lockerEntryEvents>
      <created>1483452726419</created>
      <name>102</name>
    </lockerEntryEvents>
    <lockerEntryEvents>
      <created>1483452726419</created>
      <name>102</name>
    </lockerEntryEvents>
    <lockerEntryEvents>
      <created>1483452726419</created>
      <name>102</name>
    </lockerEntryEvents>
    <lockerEntryEvents>
      <created>1483452726419</created>
      <name>102</name>
    </lockerEntryEvents>
  </lockerEntries>
<lockerEntries>
    <accountId>
      <accountId>71713470</accountId>
      <businessUnit>USIT</businessUnit>
    </accountId>
    <policyId>ps_010fe850</policyId>
    <id>0X0000014FB321985CB7AD7E9CEC19E79</id>
    <lastModified>1441820147278</lastModified>
    <authorizationStart>1441820145385</authorizationStart>
    <lockerEntryEvents>
      <created>23332345362</created>
      <name>QUEUED</name>
    </lockerEntryEvents>
  </lockerEntries>
</root>

如何编写XPath表达式来选择lockerEntryEvents的数量,以及在lockerEntries下的内容以及policyId = ps_d8d的位置 我试过了 (//lockerEntries[policyId="ps_d8d"]//count(//lockerEntryEvents))但它不起作用。现在应该是count = 4 谢谢

1 个答案:

答案 0 :(得分:3)

  

“如何编写XPath表达式以选择lockerEntryEvents lockerEntries以及policyId=ps_d8d

count(//lockerEntries[policyId='ps_d8d']/lockerEntryEvents) 的数量

这是正确的XPath:

4

<强> xpathtester demo

输出

INSERT INTO yourBucketName (KEY, VALUE) VALUES ("keyOfYourObject", 
  { "name": "abc", "password": "abcd123", "user_id": "abc123"}) RETURNING * ;