Sean D
Sean D

Reputation: 23

How to use setNodeValue in SOAPUI to update XML request

I'm new to SOAPUI and have several simple XML requests chained together. I want to use Groovy script to update an existing node on the Request side.

For example, I have GetRefData that starts:

<soapenv:Envelope xmlns:soapenv="aaa" xmlns:abc="bbb">
   <soapenv:Header>
      <abc:RequestHeader>
         <CountryCode>US</CountryCode>
         <MsgType>GetRefRq</MsgType>
      </abc:RequestHeader>
   </soapenv:Header>
    etc...

I read the responses with no issues:

def GetRequestID = context.expand( '${GetRefData#Response#declare namespace abc=\'bbb\'; //abc:GetRefRq/MsgRqHeader/RequestId[1]}' )

How do I update the RequestId on the initial Request from 12345 to 53421? I've tried:

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);
def request = context.expand('GetRefData#Request');
def requestHolder = groovyUtils.getXmlHolder(request);
requestHolder.namespaces["abc"] = "bbb";
def mypath = "//abc:GetRefRq/MsgRqHeader/RequestId[1]"
requestHolder.setNodeValue( mypath, "54321" )

But when I run it, although I get no errors and no updates.

Can someone please point this noob in the correct direction?

Upvotes: 2

Views: 4076

Answers (1)

Eiston Dsouza
Eiston Dsouza

Reputation: 404

Try this :)

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);
def request = context.expand('GetRefData#Request');
def requestHolder = groovyUtils.getXmlHolder(request);
//namespace declaration

// assuming your node is <bbb:RequestId>12345</bbb:RequestId>

def ns = "bbb"
requestHolder.setNodeValue("//"+ns+":RequestId", "54321" )
//to verify
log.info requestHolder.getNodeValue("//ns:RequestId" ) 

Upvotes: 2

Related Questions