deepak20
13 years agoNew Contributor
[Res] Replace part of the node value in response xml
Hi,
I created a mock service which reads a node value from request xml and sends the same value as one of the node value in the response xml using a groovy.
This works fine.
Now, the next step is to replace part of the node value with a different word.
Assuming, the node from request xml is BEFORE1234, and my response xml should replace the work BEFORE with AFTER and send AFTER1234 as the node value.
This is the groovy, i wrote for the first case.
########
groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def requestXml = groovyUtils.getXmlHolder(mockRequest.getRequestContent())
requestXml.declareNamespace("urn", "urn:XXX:YYY:ZZZ")
def Value = requestXml.getNodeValue("//urn:Request[1]/urn:Request_Item[1]/urn:item[1]/urn:SearchTerms[1]/urn:item[1]/urn:Values[1]/urn:item[1]")
context.setProperty( "KeyValue", Value)
#########
can someone help me in resolving the second part.
Thanks,
Deepak
I created a mock service which reads a node value from request xml and sends the same value as one of the node value in the response xml using a groovy.
This works fine.
Now, the next step is to replace part of the node value with a different word.
Assuming, the node from request xml is BEFORE1234, and my response xml should replace the work BEFORE with AFTER and send AFTER1234 as the node value.
This is the groovy, i wrote for the first case.
########
groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def requestXml = groovyUtils.getXmlHolder(mockRequest.getRequestContent())
requestXml.declareNamespace("urn", "urn:XXX:YYY:ZZZ")
def Value = requestXml.getNodeValue("//urn:Request[1]/urn:Request_Item[1]/urn:item[1]/urn:SearchTerms[1]/urn:item[1]/urn:Values[1]/urn:item[1]")
context.setProperty( "KeyValue", Value)
#########
can someone help me in resolving the second part.
Thanks,
Deepak