subex
10 years agoOccasional Contributor
SoapUI Pro 4.5.1 - Remove empty XML elements from request
Hi All,
I am developing Data driven tests using SoapUI pro 4.5.1. The Request should have the elements only if there is a value in the Test data xls. [Similar to the issue mentioned in viewtopic.php?f=2&t=21175#p48766 ]
What we have tried so far?
1. Set the Property "Remove Empty Content" to "True"
2. Added "RequestFilter.filterRequest" event with the following code:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( context.requestContent )
// find end nodes that also only consist of whitespace
for( item in holder.getDomNodes( "//*[normalize-space(.) = '' and count(*) = 0]" )){
item.removeXobj()
}
// update request and write updated request back to teststep
holder.updateProperty()
context.requestContent = holder.xml
But no empty xml child/Parent element is dropped off from the request when the node/element value is blank.
Much appreciated if someone can help me with an approach/Groovy script.
Thanks,
Rao
I am developing Data driven tests using SoapUI pro 4.5.1. The Request should have the elements only if there is a value in the Test data xls. [Similar to the issue mentioned in viewtopic.php?f=2&t=21175#p48766 ]
What we have tried so far?
1. Set the Property "Remove Empty Content" to "True"
2. Added "RequestFilter.filterRequest" event with the following code:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( context.requestContent )
// find end nodes that also only consist of whitespace
for( item in holder.getDomNodes( "//*[normalize-space(.) = '' and count(*) = 0]" )){
item.removeXobj()
}
// update request and write updated request back to teststep
holder.updateProperty()
context.requestContent = holder.xml
But no empty xml child/Parent element is dropped off from the request when the node/element value is blank.
Much appreciated if someone can help me with an approach/Groovy script.
Thanks,
Rao