使用Groovy的SoapUI我正在使用SoapUI pro和groovy脚本 . 我正在阅读客户记录,从请求到以下,
def CustRec = context.expand('${GetProductPriceOffer#Request#/tem:request[1]/quot:Customers[1]}' )
CustRec中的值是,
<quot:Customers>
<quot:Person>
<quot:CustomerType>PRIMARY</quot:CustomerType>
<quot:Sequence>0</quot:Sequence>
</quot:Person>
<quot:Person>
<quot:CustomerType>ADULT</quot:CustomerType>
<quot:Sequence>1</quot:Sequence>
</quot:Person>
</quot:Customers>
现在我想计算Customers中Person对象的总数(即在这种情况下答案是2) . 我尝试使用while循环,但它对我不起作用 . 任何人都可以告诉我如何使用循环?
提前致谢
1 回答
要计算
<Customers>
内所有<Person>
的出现次数,您可以使用count xpath函数,如下所示:另一种可能性是使用XmlSlurper而不是使用xpath,使用它可以计算
<Person>
的出现次数,但是如果你需要做更多的操作,你可以轻松地操作Xml . 要计算<Person>
,您可以使用以下方法:希望这可以帮助,