如何使用soap ui中的groovy脚本获取包含具有特定值的元素的xml根节点 [英] How to get the xml root node containing element with particular value using groovy scripts in soap ui
本文介绍了如何使用soap ui中的groovy脚本获取包含具有特定值的元素的xml根节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我的XML响应如下:
Suppose my xml response is below:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetCitiesByCountryResponse xmlns="http://www.webserviceX.NET">
<GetCitiesByCountryResult><![CDATA[<NewDataSet>
<Table>
<Country>British Indian Ocean Territory</Country>
<City>Diego Garcia</City>
</Table>
<Table>
<Country>India</Country>
<City>Ahmadabad</City>
</Table>
<Table>
<Country>India</Country>
<City>Akola</City>
</Table>
<Table>
<Country>India</Country>
<City>Aurangabad</City>
</Table>
在这里,我要获取< Country>
元素值作为使用SoapUi的Akola,包含< City>
的根节点< Table>
groovy脚本。
Here I want get the <Country>
element value from the root node <Table>
name that contains <City>
as "Akola" using SoapUi groovy scripts.
推荐答案
类似这样的事情?
Something like this?
import com.eviware.soapui.support.XmlHolder
def testCase = messageExchange.modelItem.testCase
def responseHolder = new XmlHolder(messageExchange.getResponseContentAsXml());
def resultFromServer = responseHolder["//Table/City[text()='Akola']/ancestor::Table[1]/Country/text()"]
这篇关于如何使用soap ui中的groovy脚本获取包含具有特定值的元素的xml根节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文