Avirup Das
Avirup Das

Reputation: 311

XMLHolder in groovy unable to Retrieve value

I have the following xml:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <SOAP-ENV:Body>
      <Login_v1Response>
         <result xsi:nil="true"/>
         <opSessionID>FjqkjEjipbhkdiin</opSessionID>
      </Login_v1Response>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I have the following code in groovy which returns me null:

def groovyUtils=new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder("Step1-Login#response")
log.info holder.getNodeValue("//SOAP-ENV:Envelope/SOAP-ENV:Body/Login_v1Response/opSessionID")

Please help out. Thanks.

Upvotes: 0

Views: 4927

Answers (1)

SiKing
SiKing

Reputation: 10329

You are using namespaces in your script, without defining what those namespaces are. For just reading values it is generally easier to use wildcards and not worry about them.

def groovyUtils=new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder("Step1-Login#Response")
log.info holder.getNodeValue("//*:opSessionID")

Or even something simpler like:

log.info context.expand('${Step1-Login#Response#//*:opSessionID}')

Upvotes: 3

Related Questions