Forum Discussion

Keane_India_Lim's avatar
Keane_India_Lim
New Contributor
14 years ago

How to modify the xml on onRequestscript() in SOAP UI

Here is the code which we wrote in onRequestscript

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
path = "D:\\Service\\something2.xml";
log.info("path = "+ path);
if (mockRequest.method == "POST" )
{
mockRunner.returnFile( mockRequest.httpResponse, new File(path))
return new com.eviware.soapui.impl.wsdl.mock.WsdlMockResult(mockRequest)
}


But this script changes our XML entirely... We want to modify an existing XML(something.xml)..

We were not able to modify the xml so we thought of changing the xml instead.But according to some business logic its wrong... So how can we modify the xml in onRequestscript?
  • Hi,

    That can be done in a lot of ways, but it requires a bit of Groovy/Java knowledge.

    You can read the file content to a string and then use myString.replace(). This method supports regular expressions as well.
    You can also use groovyUtils.getXmlHolder() to modify the XML using XPath (some useful links: first, second).

    Regards

    Henrik
    SmartBear Software