Reputation: 111
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>
Here I want get the <Country>
element value from the root node <Table>
name that contains <City>
as "Akola" using SoapUi groovy scripts.
Upvotes: 0
Views: 2128
Reputation: 111
Also you can try this:
import com.eviware.soapui.model.testsuite.TestRunner
def groovyUtils= new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder(XML)
def nodeValue= holder.getNodeValue("//Table/City[text()='Akola']/../Country/text()")
Upvotes: 1
Reputation: 3817
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()"]
Upvotes: 2