如何在SOAP UI中使用groovy提取嵌套XML中的标记值 [英] How to extract valuesof tags in a nested XML using groovy in SOAP UI
本文介绍了如何在SOAP UI中使用groovy提取嵌套XML中的标记值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是我在SOAP UI中从SOAP请求中获得的响应的一部分。
< a:Bundle> ;
< a:计划>
< a:行情>
< a:Quote>
< a:BenefitPeriod>
< a:描述i:nil =true/>
< a:DisplayName i:nil =true/>
< a:值> 6个月< / a:值>
< / a:BenefitPeriod>
< a:共同保险>
< a:说明> 50< / a:说明>
< a:DisplayName i:nil =true/>
< a:值> 50< / a:值>
< / a:共同保险>
< a:OutOfPocket>
< a:说明> 5000< / a:说明>
< a:DisplayName i:nil =true/>
< a:值> 5000< / a:值>
< / a:OutOfPocket>
< a:PreventiveCare i:nil =true/>
< a:Rx i:nil =true/>
< a:StopLoss>
< a:描述i:nil =true/>
< a:DisplayName i:nil =true/>
< a:值> 10000< / a:值>
< / a:StopLoss>
< / a:StandardBenefits>
< / a:引用>
< a:Quote>
//类似上面的数据报价
< / a:Quote>
< / a:引用>
< / a:计划>
< / a:Bundle>
如何获取值的文本
标签下的所有共同保险
标签在soap UI Groovy脚本步骤使用Groovy?
解决方案
另一种Groovy方法是:
pre $ def $ slpped = new XmlParser(false,false).parseText(xml)$ b $ '**'。findAll {it.name()=='a:Coinsurance'} *。'a:Value'* .text()
$ b
其中 xml
是上面的xml内容,如 String
。
Below is a part of the response that I got from the SOAP request in SOAP UI.
<a:Bundle>
<a:Plans>
<a:Quotes>
<a:Quote>
<a:StandardBenefits>
<a:BenefitPeriod>
<a:Description i:nil="true"/>
<a:DisplayName i:nil="true"/>
<a:Value>6 months</a:Value>
</a:BenefitPeriod>
<a:Coinsurance>
<a:Description>50</a:Description>
<a:DisplayName i:nil="true"/>
<a:Value>50</a:Value>
</a:Coinsurance>
<a:OutOfPocket>
<a:Description>5000</a:Description>
<a:DisplayName i:nil="true"/>
<a:Value>5000</a:Value>
</a:OutOfPocket>
<a:PreventiveCare i:nil="true"/>
<a:Rx i:nil="true"/>
<a:StopLoss>
<a:Description i:nil="true"/>
<a:DisplayName i:nil="true"/>
<a:Value>10000</a:Value>
</a:StopLoss>
</a:StandardBenefits>
</a:Quote>
<a:Quote>
//similar data like above quote
</a:Quote>
</a:Quotes>
</a:Plans>
</a:Bundle>
How do I get the text of Value
tags under all Coinsurance
tags in soap UI Groovy Script step using Groovy?
解决方案
Another Groovy approach will be:
def slurped = new XmlParser(false, false).parseText(xml)
slurped.'**'.findAll { it.name() == 'a:Coinsurance' }*.'a:Value'*.text()
where xml
is the above xml content as String
.
这篇关于如何在SOAP UI中使用groovy提取嵌套XML中的标记值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文