Forum Discussion
UnitTesters
11 years agoContributor
Hi Michael,
I have taken the groovy script route with my original issue but I am having one issue with the script I have produced in that it I have one empty node and the script is moving its position on the XML being generated which is causing error once the XML is submitted
Apologies if this is not 100% clear but any help would be greatly appreciated
Groovy script below
//Groovy Script to filter the empty elements and the empty Parent Nodes
import com.eviware.soapui.support.xml.XmlUtils
//Reading the Request from Properties
def request = context.expand( '${Properties#Request}' )
request = XmlUtils.prettyPrintXml(request)
def parsedXml = new XmlParser().parseText(request)
def buffer = new StringWriter()
new XmlNodePrinter(new PrintWriter(buffer)).print(parsedXml)
def filteredRequest = buffer.toString()
filteredRequest = XmlUtils.prettyPrintXml(filteredRequest)
//Removing all the xml elements that have a value of "--N/A--"
filteredRequest = filteredRequest.replaceAll( "<(.+)>N/A<(.+)>", "")
filteredRequest = XmlUtils.prettyPrintXml(filteredRequest)
request = filteredRequest
//Removing all the empty elements and parent nodes
for(i=0;i<6;i++)
{
parsedXml = new XmlParser().parseText(request)
buffer = new StringWriter()
new XmlNodePrinter(new PrintWriter(buffer)).print(parsedXml)
filteredRequest = buffer.toString()
filteredRequest = XmlUtils.prettyPrintXml(filteredRequest)
//Removing all the xml elements that have a value of ""
filteredRequest = filteredRequest.replaceAll( "<(.+)><(.+)>", "")
filteredRequest = filteredRequest.replaceAll( "<(.+)/>", "")
//filteredRequest = XmlUtils.prettyPrintXml(filteredRequest)
request = filteredRequest
}
//Will pass this fully filtered request into the Application test step for submission using property transfer
return filteredRequest
I have taken the groovy script route with my original issue but I am having one issue with the script I have produced in that it I have one empty node and the script is moving its position on the XML being generated which is causing error once the XML is submitted
Apologies if this is not 100% clear but any help would be greatly appreciated
Groovy script below
//Groovy Script to filter the empty elements and the empty Parent Nodes
import com.eviware.soapui.support.xml.XmlUtils
//Reading the Request from Properties
def request = context.expand( '${Properties#Request}' )
request = XmlUtils.prettyPrintXml(request)
def parsedXml = new XmlParser().parseText(request)
def buffer = new StringWriter()
new XmlNodePrinter(new PrintWriter(buffer)).print(parsedXml)
def filteredRequest = buffer.toString()
filteredRequest = XmlUtils.prettyPrintXml(filteredRequest)
//Removing all the xml elements that have a value of "--N/A--"
filteredRequest = filteredRequest.replaceAll( "<(.+)>N/A<(.+)>", "")
filteredRequest = XmlUtils.prettyPrintXml(filteredRequest)
request = filteredRequest
//Removing all the empty elements and parent nodes
for(i=0;i<6;i++)
{
parsedXml = new XmlParser().parseText(request)
buffer = new StringWriter()
new XmlNodePrinter(new PrintWriter(buffer)).print(parsedXml)
filteredRequest = buffer.toString()
filteredRequest = XmlUtils.prettyPrintXml(filteredRequest)
//Removing all the xml elements that have a value of ""
filteredRequest = filteredRequest.replaceAll( "<(.+)><(.+)>", "")
filteredRequest = filteredRequest.replaceAll( "<(.+)/>", "")
//filteredRequest = XmlUtils.prettyPrintXml(filteredRequest)
request = filteredRequest
}
//Will pass this fully filtered request into the Application test step for submission using property transfer
return filteredRequest
Related Content
- 7 years ago
Recent Discussions
- 7 days ago