vijay prasad
vijay prasad

Reputation: 35

How can I write the output using Groovy XmlNodePrinter?

How can I write the output of an object to a teststep (Soaprequest) in soapUI using XmlNodePrinter.

I have the below groovy script in which I have an input xml file. I perform file operations and then would like to write the object using xmlnodeprinter, to a teststep (soaprequest) in soapUI (highlighted in bold...not sure wat should be going in place of ---)

I tried writing to an external file which works (highlighted in green)

def alert = com.eviware.soapui.support.UISupport;
//Define a file pointer for groovy to handle the file operations.
def inputFile = new File("V:\\Sample\\Sample.xml")
if(!inputFile.exists())
{
//Display an alert if the file is not found.
alert.showInfoMessage("Input File 'Sample.xml' not found!");
}
else
{
xml=new XmlParser().parseText(inputFile.text)
def nodeToDel=xml.A.B.find{it.@C3='1'}
def parent = nodeToDel.parent()
parent.remove(nodeToDel)
//new XmlNodePrinter(new PrintWriter(new FileWriter(new File('V:\\Sample\\e.xml')))).print(parent)
new XmlNodePrinter(new PrintWriter(new FileWriter(---))).print(parent)
}

Upvotes: 1

Views: 4749

Answers (1)

Vamsi Emani
Vamsi Emani

Reputation: 10302

define a string writer

def sw = new StringWriter()

new XmlNodePrinter(new PrintWriter(sw)).print(parent)

def modifiedXml = sw.toString()

modifiedXml variable will contain the xml with deleted nodes which you can further use for your test step.

Upvotes: 2

Related Questions