如何在Groovy Code SoapUI 中编写Xpath 查询?

How to write Xpath Query in Groovy Code SoapUI?

我是 groovy 脚本编写的新手,正在尝试编写应该使用此 Xpath 提供输出的代码:

/BillingInvoice/invoicedOrders/entry/value/lines/aggregationKey[text()='INV_GROUP_Meterreading' or text()='INV_GROUP_Power']/../(aggregationKey|amount)

此 Xpath 在在线 Xpath 格式检查中工作正常,但我无法在 Groovy 脚本中工作,因为我对它了解不多。

这里写一个Groovy脚本的目的是提取聚合键对应的所有金额并求和,但目前我连标签元素和值都卡住了

下面是我正在使用的XML,保存在SOAPUI 属性中。我在 Groovy 脚本中解析它:

<BillingInvoice>
   <aggregation>
      <aggregations>
         <aggregations>
            <key>INV_GROUP_Power</key>
            <showUnitPrice>true</showUnitPrice>
            <showVolume>true</showVolume>
            <volumeUoM>kW</volumeUoM>
         </aggregations>
         <aggregations>
            <key>INV_GROUP_Meterreading</key>
            <showUnitPrice>true</showUnitPrice>
            <showVolume>true</showVolume>
            <volumeUoM>days</volumeUoM>
         </aggregations>
         <key>DISTRIBUTION</key>
         <showUnitPrice>false</showUnitPrice>
         <showVolume>false</showVolume>
      </aggregations>
   </aggregation>
   <amount>153.6600000000</amount>
   <balance>153.6600000000</balance>
   <bundleId>000000~DEFAULT</bundleId>
   <consumptionEvolution>
      <consumption>
         <deliveryPointId>555555555555555</deliveryPointId>
         <endPeriod>2017-07-31T00:00:00+02:00</endPeriod>
         <startPeriod>2016-08-01T00:00:00+02:00</startPeriod>
         <timeFrame>TOTAL_HOUR</timeFrame>
         <value>74645.2300000000</value>
         <meteringContext>PERIODIC_METERING</meteringContext>
      </consumption>
      <consumption>
         <deliveryPointId>555555555555555</deliveryPointId>
         <endPeriod>2015-05-07T00:00:00+02:00</endPeriod>
         <startPeriod>2015-03-19T00:00:00+01:00</startPeriod>
         <timeFrame>TOTAL_HOUR</timeFrame>
         <value>471.8600000000</value>
         <meteringContext>GAIN</meteringContext>
      </consumption>
      <consumption>
         <deliveryPointId>555555555555555</deliveryPointId>
         <endPeriod>2015-03-19T00:00:00+01:00</endPeriod>
         <startPeriod>2014-11-01T00:00:00+01:00</startPeriod>
         <timeFrame>TOTAL_HOUR</timeFrame>
         <value>3860.2600000000</value>
         <meteringContext>GAIN</meteringContext>
      </consumption>
   </consumptionEvolution>
   <customer>
      <accountNr>999999999</accountNr>
      <billingId>444444444</billingId>
   </customer>
   <dueDate>2017-08-21T00:00:00+02:00</dueDate>
   <dunningBlockedByAgent>false</dunningBlockedByAgent>
   <dunningBlockedBySystem>false</dunningBlockedBySystem>
   <dunningStatus>NID</dunningStatus>
   <eanTotalEvolution>
      <totalEvolution>
         <connectionKey>555555555555555</connectionKey>
         <eanTotalConsumption/>
      </totalEvolution>
   </eanTotalEvolution>
   <invoiceDate>2017-08-07T00:00:00+02:00</invoiceDate>
   <invoiceNumber>GHJKJ111111</invoiceNumber>
   <invoiceType>SETTLEMENT</invoiceType>
   <invoicedOrders>
      <entry>
         <key>59412</key>
         <value>
            <address>
               <city>Whosebug</city>
               <country>US</country>
               <deliveryPointID>555555555555555</deliveryPointID>
               <gridcompany>4444444444444</gridcompany>
               <region>Cold</region>
               <streetName>Placeforeveryone</streetName>
               <streetNumber>420</streetNumber>
               <zipcode>xxxxxx</zipcode>
            </address>
            <billingEstimates>
               <billingEstimate>
                  <fromDate>2015-11-01T00:00:00+01:00</fromDate>
                  <logDate>2017-08-07T00:00:00+02:00</logDate>
                  <meteringContext>GAIN</meteringContext>
                  <source>MARKET</source>
                  <timeframe>TOTAL_HOUR</timeframe>
                  <validFrom>2015-11-01T00:00:00+01:00</validFrom>
                  <validTo>2015-11-01T00:00:00+01:00</validTo>
                  <value>46802.0000000000</value>
               </billingEstimate>
               <billingEstimate>
                  <fromDate>2015-11-01T00:00:00+01:00</fromDate>
                  <logDate>2017-08-07T00:00:00+02:00</logDate>
                  <meteringContext>GAIN</meteringContext>
                  <source>MARKET</source>
                  <timeframe>TOTAL_HOUR</timeframe>
                  <validFrom>2015-11-01T00:00:00+01:00</validFrom>
                  <validTo>9999-12-31T00:00:00+01:00</validTo>
                  <value>12409.0000000000</value>
               </billingEstimate>
            </billingEstimates>
            <contractLine>00000-0000-0000-57af-00000</contractLine>
            <contractNumber>00000-00000-00000-8cbe-00000</contractNumber>
            <contractedVolumes>
               <fromDate>2015-11-01T00:00:00+01:00</fromDate>
               <timeFrame>TOTAL_HOUR</timeFrame>
               <toDate>9999-12-31T00:00:00+01:00</toDate>
               <value>200000.0000000000</value>
            </contractedVolumes>
            <historicalConsumptions>
               <deliveryPointId>555555555555555</deliveryPointId>
               <endPeriod>2014-11-01T00:00:00+01:00</endPeriod>
               <startPeriod>2014-04-11T00:00:00+02:00</startPeriod>
               <timeFrame>TOTAL_HOUR</timeFrame>
               <value>1057.6900000000</value>
            </historicalConsumptions>
            <historicalConsumptions>
               <deliveryPointId>555555555555555</deliveryPointId>
               <endPeriod>2015-03-19T00:00:00+01:00</endPeriod>
               <startPeriod>2014-11-01T00:00:00+01:00</startPeriod>
               <timeFrame>TOTAL_HOUR</timeFrame>
               <value>3860.2600000000</value>
            </historicalConsumptions>
            <historicalConsumptions>
               <deliveryPointId>555555555555555</deliveryPointId>
               <endPeriod>2015-05-07T00:00:00+02:00</endPeriod>
               <startPeriod>2015-03-19T00:00:00+01:00</startPeriod>
               <timeFrame>TOTAL_HOUR</timeFrame>
               <value>471.8600000000</value>
            </historicalConsumptions>
            <lines>
               <aggregationKey>INV_GROUP_VAT_21%</aggregationKey>
               <amount>8.2400000000</amount>
               <billingType>settlement</billingType>
               <description>VAT 21% 2017-01-01/2017-07-31</description>
               <invoiceLineId>200196</invoiceLineId>
               <isPercentage>1</isPercentage>
               <isVatPercentage>true</isVatPercentage>
               <orderLineType>SETTLEMENT</orderLineType>
               <periodEnd>2017-07-31T00:00:00+02:00</periodEnd>
               <periodStart>2017-01-01T00:00:00+01:00</periodStart>
               <price>21.0000000000</price>
               <productCode>VAT_21%</productCode>
               <quantity>39.2500000000</quantity>
               <vatBaseAmount>39.2500000000</vatBaseAmount>
               <vatCode>VAT-OUT-21-S</vatCode>
               <vatPerc>21.0000000000</vatPerc>
            </lines>
            <lines>
               <aggregationKey>INV_GROUP_VAT_0%</aggregationKey>
               <amount>0.0000000000</amount>
               <billingType>settlement</billingType>
               <description>VAT 0%  2017-01-01/2017-07-31</description>
               <invoiceLineId>200195</invoiceLineId>
               <isPercentage>1</isPercentage>
               <isVatPercentage>true</isVatPercentage>
               <orderLineType>SETTLEMENT</orderLineType>
               <periodEnd>2017-07-31T00:00:00+02:00</periodEnd>
               <periodStart>2017-01-01T00:00:00+01:00</periodStart>
               <price>0.0000000000</price>
               <productCode>VAT_0%</productCode>
               <quantity>0.0000000000</quantity>
               <vatBaseAmount>0.0000000000</vatBaseAmount>
               <vatCode>VAT-OUT-00-S</vatCode>
               <vatPerc>0.0000000000</vatPerc>
            </lines>
            <lines>
               <aggregationKey>INV_GROUP_Meterreading</aggregationKey>
               <amount>2.8000000000</amount>
               <billingType>settlement</billingType>
               <description>D Gas meterreading 2017-01-01/2017-07-31</description>
               <invoiceLineId>200194</invoiceLineId>
               <isPercentage>0</isPercentage>
               <isVatPercentage>false</isVatPercentage>
               <orderLineType>SETTLEMENT</orderLineType>
               <periodEnd>2017-07-31T00:00:00+02:00</periodEnd>
               <periodStart>2017-01-01T00:00:00+01:00</periodStart>
               <price>0.0132876700</price>
               <productCode>D_Gas_meterreading</productCode>
               <quantity>211.0000000000</quantity>
               <vatCode>VAT-OUT-21-S</vatCode>
            </lines>
            <lines>
               <aggregationKey>INV_GROUP_Power</aggregationKey>
               <amount>36.4500000000</amount>
               <billingType>settlement</billingType>
               <description>D Gas fixed term 2017-01-01/2017-07-31</description>
               <invoiceLineId>200193</invoiceLineId>
               <isPercentage>0</isPercentage>
               <isVatPercentage>false</isVatPercentage>
               <orderLineType>SETTLEMENT</orderLineType>
               <periodEnd>2017-07-31T00:00:00+02:00</periodEnd>
               <periodStart>2017-01-01T00:00:00+01:00</periodStart>
               <price>0.1727671200</price>
               <productCode>D_Gas_fixed_term</productCode>
               <quantity>211.0000000000</quantity>
               <vatCode>VAT-OUT-21-S</vatCode>
            </lines>
            <lines>
               <aggregationKey>INV_GROUP_VAT_0%</aggregationKey>
               <amount>0.0000000000</amount>
               <billingType>settlement</billingType>
               <description>VAT 0%  2016-03-01/2017-01-01</description>
               <invoiceLineId>200192</invoiceLineId>
               <isPercentage>1</isPercentage>
               <isVatPercentage>true</isVatPercentage>
               <orderLineType>SETTLEMENT</orderLineType>
               <periodEnd>2017-01-01T00:00:00+01:00</periodEnd>
               <periodStart>2016-03-01T00:00:00+01:00</periodStart>
               <price>0.0000000000</price>
               <productCode>VAT_0%</productCode>
               <quantity>0.0000000000</quantity>
               <vatBaseAmount>0.0000000000</vatBaseAmount>
               <vatCode>VAT-OUT-00-S</vatCode>
               <vatPerc>0.0000000000</vatPerc>
            </lines>
            <lines>
               <aggregationKey>INV_GROUP_VAT_21%</aggregationKey>
               <amount>13.0300000000</amount>
               <billingType>settlement</billingType>
               <description>VAT 21% 2016-03-01/2017-01-01</description>
               <invoiceLineId>200191</invoiceLineId>
               <isPercentage>1</isPercentage>
               <isVatPercentage>true</isVatPercentage>
               <orderLineType>SETTLEMENT</orderLineType>
               <periodEnd>2017-01-01T00:00:00+01:00</periodEnd>
               <periodStart>2016-03-01T00:00:00+01:00</periodStart>
               <price>21.0000000000</price>
               <productCode>VAT_21%</productCode>
               <quantity>62.0500000000</quantity>
               <vatBaseAmount>62.0500000000</vatBaseAmount>
               <vatCode>VAT-OUT-21-S</vatCode>
               <vatPerc>21.0000000000</vatPerc>
            </lines>
            <lines>
               <aggregationKey>INV_GROUP_Meterreading</aggregationKey>
               <amount>6.7900000000</amount>
               <billingType>settlement</billingType>
               <description>D Gas meterreading 2016-03-01/2017-01-01</description>
               <invoiceLineId>200190</invoiceLineId>
               <isPercentage>0</isPercentage>
               <isVatPercentage>false</isVatPercentage>
               <orderLineType>SETTLEMENT</orderLineType>
               <periodEnd>2017-01-01T00:00:00+01:00</periodEnd>
               <periodStart>2016-03-01T00:00:00+01:00</periodStart>
               <price>0.0221857900</price>
               <productCode>D_Gas_meterreading</productCode>
               <quantity>306.0000000000</quantity>
               <vatCode>VAT-OUT-21-S</vatCode>
            </lines>
            <lines>
               <aggregationKey>INV_GROUP_Power</aggregationKey>
               <amount>55.2600000000</amount>
               <billingType>settlement</billingType>
               <description>D Gas fixed term 2016-03-01/2017-01-01</description>
               <invoiceLineId>200189</invoiceLineId>
               <isPercentage>0</isPercentage>
               <isVatPercentage>false</isVatPercentage>
               <orderLineType>SETTLEMENT</orderLineType>
               <periodEnd>2017-01-01T00:00:00+01:00</periodEnd>
               <periodStart>2016-03-01T00:00:00+01:00</periodStart>
               <price>0.1805737700</price>
               <productCode>D_Gas_fixed_term</productCode>
               <quantity>306.0000000000</quantity>
               <vatCode>VAT-OUT-21-S</vatCode>
            </lines>
            <lines>
               <aggregationKey>INV_GROUP_VAT_21%</aggregationKey>
               <amount>1.2300000000</amount>
               <billingType>settlement</billingType>
               <description>VAT 21% 2016-02-01/2016-03-01</description>
               <invoiceLineId>200188</invoiceLineId>
               <isPercentage>1</isPercentage>
               <isVatPercentage>true</isVatPercentage>
               <orderLineType>SETTLEMENT</orderLineType>
               <periodEnd>2016-03-01T00:00:00+01:00</periodEnd>
               <periodStart>2016-02-01T00:00:00+01:00</periodStart>
               <price>21.0000000000</price>
               <productCode>VAT_21%</productCode>
               <quantity>5.8800000000</quantity>
               <vatBaseAmount>5.8800000000</vatBaseAmount>
               <vatCode>VAT-OUT-21-S</vatCode>
               <vatPerc>21.0000000000</vatPerc>
            </lines>
            <lines>
               <aggregationKey>INV_GROUP_VAT_0%</aggregationKey>
               <amount>0.0000000000</amount>
               <billingType>settlement</billingType>
               <description>VAT 0%  2016-02-01/2016-03-01</description>
               <invoiceLineId>200187</invoiceLineId>
               <isPercentage>1</isPercentage>
               <isVatPercentage>true</isVatPercentage>
               <orderLineType>SETTLEMENT</orderLineType>
               <periodEnd>2016-03-01T00:00:00+01:00</periodEnd>
               <periodStart>2016-02-01T00:00:00+01:00</periodStart>
               <price>0.0000000000</price>
               <productCode>VAT_0%</productCode>
               <quantity>0.0000000000</quantity>
               <vatBaseAmount>0.0000000000</vatBaseAmount>
               <vatCode>VAT-OUT-00-S</vatCode>
               <vatPerc>0.0000000000</vatPerc>
            </lines>
            <lines>
               <aggregationKey>INV_GROUP_Meterreading</aggregationKey>
               <amount>0.6400000000</amount>
               <billingType>settlement</billingType>
               <description>D Gas meterreading 2016-02-01/2016-03-01</description>
               <invoiceLineId>200186</invoiceLineId>
               <isPercentage>0</isPercentage>
               <isVatPercentage>false</isVatPercentage>
               <orderLineType>SETTLEMENT</orderLineType>
               <periodEnd>2016-03-01T00:00:00+01:00</periodEnd>
               <periodStart>2016-02-01T00:00:00+01:00</periodStart>
               <price>0.0221857900</price>
               <productCode>D_Gas_meterreading</productCode>
               <quantity>29.0000000000</quantity>
               <vatCode>VAT-OUT-21-S</vatCode>
            </lines>
            <lines>
               <aggregationKey>INV_GROUP_Power</aggregationKey>
               <amount>5.2400000000</amount>
               <billingType>settlement</billingType>
               <description>D Gas fixed term 2016-02-01/2016-03-01</description>
               <invoiceLineId>200185</invoiceLineId>
               <isPercentage>0</isPercentage>
               <isVatPercentage>false</isVatPercentage>
               <orderLineType>SETTLEMENT</orderLineType>
               <periodEnd>2016-03-01T00:00:00+01:00</periodEnd>
               <periodStart>2016-02-01T00:00:00+01:00</periodStart>
               <price>0.1805737700</price>
               <productCode>D_Gas_fixed_term</productCode>
               <quantity>29.0000000000</quantity>
               <vatCode>VAT-OUT-21-S</vatCode>
            </lines>
            <lines>
               <aggregationKey>INV_GROUP_VAT_21%</aggregationKey>
               <amount>1.3200000000</amount>
               <billingType>settlement</billingType>
               <description>VAT 21% 2016-01-01/2016-02-01</description>
               <invoiceLineId>200184</invoiceLineId>
               <isPercentage>1</isPercentage>
               <isVatPercentage>true</isVatPercentage>
               <orderLineType>SETTLEMENT</orderLineType>
               <periodEnd>2016-02-01T00:00:00+01:00</periodEnd>
               <periodStart>2016-01-01T00:00:00+01:00</periodStart>
               <price>21.0000000000</price>
               <productCode>VAT_21%</productCode>
               <quantity>6.2900000000</quantity>
               <vatBaseAmount>6.2900000000</vatBaseAmount>
               <vatCode>VAT-OUT-21-S</vatCode>
               <vatPerc>21.0000000000</vatPerc>
            </lines>
            <lines>
               <aggregationKey>INV_GROUP_VAT_0%</aggregationKey>
               <amount>0.0000000000</amount>
               <billingType>settlement</billingType>
               <description>VAT 0%  2016-01-01/2016-02-01</description>
               <invoiceLineId>200183</invoiceLineId>
               <isPercentage>1</isPercentage>
               <isVatPercentage>true</isVatPercentage>
               <orderLineType>SETTLEMENT</orderLineType>
               <periodEnd>2016-02-01T00:00:00+01:00</periodEnd>
               <periodStart>2016-01-01T00:00:00+01:00</periodStart>
               <price>0.0000000000</price>
               <productCode>VAT_0%</productCode>
               <quantity>0.0000000000</quantity>
               <vatBaseAmount>0.0000000000</vatBaseAmount>
               <vatCode>VAT-OUT-00-S</vatCode>
               <vatPerc>0.0000000000</vatPerc>
            </lines>
            <lines>
               <aggregationKey>INV_GROUP_Meterreading</aggregationKey>
               <amount>0.6900000000</amount>
               <billingType>settlement</billingType>
               <description>D Gas meterreading 2016-01-01/2016-02-01</description>
               <invoiceLineId>200182</invoiceLineId>
               <isPercentage>0</isPercentage>
               <isVatPercentage>false</isVatPercentage>
               <orderLineType>SETTLEMENT</orderLineType>
               <periodEnd>2016-02-01T00:00:00+01:00</periodEnd>
               <periodStart>2016-01-01T00:00:00+01:00</periodStart>
               <price>0.0221857900</price>
               <productCode>D_Gas_meterreading</productCode>
               <quantity>31.0000000000</quantity>
               <vatCode>VAT-OUT-21-S</vatCode>
            </lines>
            <lines>
               <aggregationKey>INV_GROUP_Power</aggregationKey>
               <amount>5.6000000000</amount>
               <billingType>settlement</billingType>
               <description>D Gas fixed term 2016-01-01/2016-02-01</description>
               <invoiceLineId>200181</invoiceLineId>
               <isPercentage>0</isPercentage>
               <isVatPercentage>false</isVatPercentage>
               <orderLineType>SETTLEMENT</orderLineType>
               <periodEnd>2016-02-01T00:00:00+01:00</periodEnd>
               <periodStart>2016-01-01T00:00:00+01:00</periodStart>
               <price>0.1805737700</price>
               <productCode>D_Gas_fixed_term</productCode>
               <quantity>31.0000000000</quantity>
               <vatCode>VAT-OUT-21-S</vatCode>
            </lines>
            <lines>
               <aggregationKey>INV_GROUP_VAT_0%</aggregationKey>
               <amount>0.0000000000</amount>
               <billingType>settlement</billingType>
               <description>VAT 0%  2015-11-01/2016-01-01</description>
               <invoiceLineId>200180</invoiceLineId>
               <isPercentage>1</isPercentage>
               <isVatPercentage>true</isVatPercentage>
               <orderLineType>SETTLEMENT</orderLineType>
               <periodEnd>2016-01-01T00:00:00+01:00</periodEnd>
               <periodStart>2015-11-01T00:00:00+01:00</periodStart>
               <price>0.0000000000</price>
               <productCode>VAT_0%</productCode>
               <quantity>0.0000000000</quantity>
               <vatBaseAmount>0.0000000000</vatBaseAmount>
               <vatCode>VAT-OUT-00-S</vatCode>
               <vatPerc>0.0000000000</vatPerc>
            </lines>
            <lines>
               <aggregationKey>INV_GROUP_VAT_21%</aggregationKey>
               <amount>2.8400000000</amount>
               <billingType>settlement</billingType>
               <description>VAT 21% 2015-11-01/2016-01-01</description>
               <invoiceLineId>200179</invoiceLineId>
               <isPercentage>1</isPercentage>
               <isVatPercentage>true</isVatPercentage>
               <orderLineType>SETTLEMENT</orderLineType>
               <periodEnd>2016-01-01T00:00:00+01:00</periodEnd>
               <periodStart>2015-11-01T00:00:00+01:00</periodStart>
               <price>21.0000000000</price>
               <productCode>VAT_21%</productCode>
               <quantity>13.5300000000</quantity>
               <vatBaseAmount>13.5300000000</vatBaseAmount>
               <vatCode>VAT-OUT-21-S</vatCode>
               <vatPerc>21.0000000000</vatPerc>
            </lines>
            <lines>
               <aggregationKey>INV_GROUP_Meterreading</aggregationKey>
               <amount>1.6600000000</amount>
               <billingType>settlement</billingType>
               <description>D Gas meterreading 2015-11-01/2016-01-01</description>
               <invoiceLineId>200178</invoiceLineId>
               <isPercentage>0</isPercentage>
               <isVatPercentage>false</isVatPercentage>
               <orderLineType>SETTLEMENT</orderLineType>
               <periodEnd>2016-01-01T00:00:00+01:00</periodEnd>
               <periodStart>2015-11-01T00:00:00+01:00</periodStart>
               <price>0.0272602700</price>
               <productCode>D_Gas_meterreading</productCode>
               <quantity>61.0000000000</quantity>
               <vatCode>VAT-OUT-21-S</vatCode>
            </lines>
            <lines>
               <aggregationKey>INV_GROUP_Power</aggregationKey>
               <amount>11.8700000000</amount>
               <billingType>settlement</billingType>
               <description>D Gas fixed term 2015-11-01/2016-01-01</description>
               <invoiceLineId>200177</invoiceLineId>
               <isPercentage>0</isPercentage>
               <isVatPercentage>false</isVatPercentage>
               <orderLineType>SETTLEMENT</orderLineType>
               <periodEnd>2016-01-01T00:00:00+01:00</periodEnd>
               <periodStart>2015-11-01T00:00:00+01:00</periodStart>
               <price>0.1946575300</price>
               <productCode>D_Gas_fixed_term</productCode>
               <quantity>61.0000000000</quantity>
               <vatCode>VAT-OUT-21-S</vatCode>
            </lines>
            <meterType>YEAR</meterType>
            <newAdvanced>
               <recurringAmount>42.0000000000</recurringAmount>
               <recurringUnit>MONTH</recurringUnit>
               <recurringValue>1</recurringValue>
            </newAdvanced>
            <orderType>SETTLEMENT</orderType>
            <periodEnd>2017-07-31T00:00:00+02:00</periodEnd>
            <periodStart>2015-11-01T00:00:00+01:00</periodStart>
            <productType>NG</productType>
            <subAmount>153.6600000000</subAmount>
         </value>
      </entry>
   </invoicedOrders>
   <paymentReference>+++000/000000/00000000+++</paymentReference>
   <relationRef>88888888</relationRef>
   <status>2</status>
   <unsettledInvoices/>
   <withAttachment>false</withAttachment>
   <yearlyConsumptionEvolution>
      <yearlyConsumptionPerEan>
         <connectionKey>555555555555555</connectionKey>
         <yearlyConsumptions>
            <yearlyConsumption>
               <timeFrameConsumptions>
                  <timeFrameConsumption>
                     <consumption>44639.0266771523</consumption>
                     <timeFrame>TOTAL_HOUR</timeFrame>
                  </timeFrameConsumption>
               </timeFrameConsumptions>
               <year>2017</year>
            </yearlyConsumption>
            <yearlyConsumption>
               <timeFrameConsumptions>
                  <timeFrameConsumption>
                     <consumption>5257.2047645253</consumption>
                     <timeFrame>TOTAL_HOUR</timeFrame>
                  </timeFrameConsumption>
               </timeFrameConsumptions>
               <year>2015</year>
            </yearlyConsumption>
            <yearlyConsumption>
               <timeFrameConsumptions>
                  <timeFrameConsumption>
                     <consumption>4971.3241391945</consumption>
                     <timeFrame>TOTAL_HOUR</timeFrame>
                  </timeFrameConsumption>
               </timeFrameConsumptions>
               <year>2014</year>
            </yearlyConsumption>
         </yearlyConsumptions>
      </yearlyConsumptionPerEan>
   </yearlyConsumptionEvolution>
</BillingInvoice>

这是 groovy 脚本,它可以满足您的需求。

方法 #1 使用 XmlSlurper

即,使用可能的值之一搜索 aggregationKey 并找到相应 amount 的值并将它们相加。

//Define what key & possible values to filter
def filterMap = [aggregationKey:['INV_GROUP_Meterreading','INV_GROUP_Power']]

//Pass xmlString below, not added for saving space
def xml = new XmlSlurper().parseText(xmlString)

def result = filterMap.collect{ k,v -> xml.'**'.findAll{it.name() == k && it in v}*.parent()*.amount*.text()}.flatten().sum{it as Double}
log.info result

你可以快速在线试用这个demo

方法 #2 使用 xpath

请注意,用于检索所需金额和总和的正确 xpath 是 sum(//lines[aggregationKey[.='INV_GROUP_Meterreading' or .='INV_GROUP_Power']]/amount)

当然,如果有命名空间,那也需要处理。

脚本

import com.eviware.soapui.support.XmlHolder
//Pass xmlString, avoiding to save the space
def holder = new XmlHolder(xmlString)
def result = holder.getNodeValue("sum(//*:lines[aggregationKey[.='INV_GROUP_Meterreading' or .='INV_GROUP_Power']]/*:amount)") as Double
log.info result