Reputation: 3253
If I've a Soap response like below
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns0:SomeResponse xmlns:ns0="urn:ABC:EFG:HIJ:Some_WS">
<ns0:ID>6384</ns0: ID>
<ns0:Some_ID>10530</ns0: Some_ID >
<ns0:Status>SomeStatus</ns0:Status>
<ns0:Number>INT1037;INT1027;</ns0: Number>
</ns0:SomeResponse >
</soapenv:Body>
</soapenv:Envelope>
How can I retrieve Some_ID
value. I am using the below code in SoapUI to retrieve the value of Some_ID
.
...
def response = tstep.getPropertyValue("response");
def gutils = new com.eviware.soapui.support.GroovyUtils( context );
def holder = gutils.getXmlHolder("$response");
// define namespace
holder.namespaces["ns0"] = "http://www.w3.org/2001/XMLSchema-instance"
def val1 = holder.getNodeValue("//ns0:SomeResponse/ns0:Some_ID");
log.info(val1)
But log.info
is giving me null
value.
Upvotes: 1
Views: 1019
Reputation: 10329
To retrieve just that one specific value, you can use a simple:
def val1 = context.expand('${TestStepName#Response#//*:Some_ID}')
For more complex parsing, you would have use to either XmlHolder
or XmlParser
or XmlSlurper
. You can get an idea about these from the official documentation.
In your script, try using tstep.getPropertyValue("Response")
, with upper-case R.
Upvotes: 4
Reputation: 3253
I got it working. I had to change namespaces
declaration to below and thats it.
holder.namespaces["ns0"] = "urn:ABC:EFG:HIJ:Some_WS"
Upvotes: 0