VincentVonk
11 years agoOccasional Contributor
Stripping dynamicly XML parrent tags with SoapUI PRO
Hi,
I have a question, currently we are using in SoapUI pro for our test data an excelsheet DataSource, to fill the XML requests. In some cases an XML element is not needed in the request, because in an testcase it is not needed (leaving it empty is not allowed and gives back errors in our services).
What we currently do to solve this is:
DataSource with excelsheet
A disabled Teststep with all fields filled dynamically from the Excelsheet
Groovy Script step with the following code:
import com.eviware.soapui.support.xml.XmlUtils
def request = context.expand( '${Place holder#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)
filteredRequest = filteredRequest.replaceAll( "<(.+)>--REMOVE--<(.+)>", "")
filteredRequest = XmlUtils.prettyPrintXml(filteredRequest)
context.requestContent = filteredRequest
Then another test step with the same Envelope/Header as the first request but for the body the result of the groovy test script.
If we use in the excel file --REMOVE-- it works fine for most cases. However in some situations it is required to remove the parent node , otherwise it still gives back errors. Do you know have any idea how we could achieve this?
Thank you for your help
I have a question, currently we are using in SoapUI pro for our test data an excelsheet DataSource, to fill the XML requests. In some cases an XML element is not needed in the request, because in an testcase it is not needed (leaving it empty is not allowed and gives back errors in our services).
What we currently do to solve this is:
DataSource with excelsheet
A disabled Teststep with all fields filled dynamically from the Excelsheet
Groovy Script step with the following code:
import com.eviware.soapui.support.xml.XmlUtils
def request = context.expand( '${Place holder#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)
filteredRequest = filteredRequest.replaceAll( "<(.+)>--REMOVE--<(.+)>", "")
filteredRequest = XmlUtils.prettyPrintXml(filteredRequest)
context.requestContent = filteredRequest
Then another test step with the same Envelope/Header as the first request but for the body the result of the groovy test script.
If we use in the excel file --REMOVE-- it works fine for most cases. However in some situations it is required to remove the parent node , otherwise it still gives back errors. Do you know have any idea how we could achieve this?
Thank you for your help