cancel
Showing results for 
Search instead for 
Did you mean: 

SoapUI Pro 4.5.1 - Remove empty XML elements from request

Highlighted
Occasional 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
6 REPLIES 6
Highlighted
Community Hero

Re: SoapUI Pro 4.5.1 - Remove empty XML elements from reques

If you are a pro user, try posting in sopaui pro boards.


Regards,
Rao.
Highlighted
Community Hero

Re: SoapUI Pro 4.5.1 - Remove empty XML elements from reques

When you say "The Request should have the elements only if there is a value in the Test data xls", does it mean are you wanted to created request with only mandatory elements in the request or possibily with some additional optional elements too. Or you wanted to try the invalid request or valid request in all the cases?


Regards,
Rao.
Highlighted
Occasional Contributor

Re: SoapUI Pro 4.5.1 - Remove empty XML elements from reques

Hi, I have used the Event-> RequestFilter.filterRequest and "Remove Empty Content" property to remove the empty nodes in my request. It is helping upto certain extent but not really removing the Parent node "Product" in the below example. Can someone help me with a work around to achieve it?

Original Request
<soapenv:Body>
<v1:Retrieve>
<v1:RetrieveCriteria>
<v1:RetrieveAll>true</v1:RetrieveAll>
<v1:Product>
<v1:Productid></v1:Productid>
<v1:Productid></v1:Productid>
</v1:Product>
</v1:RetrieveCriteria>
</v1:Retrieve>
</soapenv:Body>


Expected :

<soapenv:Body>
<v1:Retrieve>
<v1:RetrieveCriteria>
<v1:RetrieveAll>true</v1:RetrieveAll>
</v1:RetrieveCriteria>
</v1:Retrieve>
</soapenv:Body>

Actual :
<soapenv:Body>
<v1:Retrieve>
<v1:RetrieveCriteria>
<v1:RetrieveAll>true</v1:RetrieveAll>
<v1:Product>

</v1:Product>

</v1:RetrieveCriteria>
</v1:Retrieve>
</soapenv:Body>
Highlighted
Community Hero

Re: SoapUI Pro 4.5.1 - Remove empty XML elements from reques

Looks your script is removing the element if there is no data. then you may need to additional check if the parent does not have any childs then remote it too.

Other way build the elements only if you have the data for certain element.


Regards,
Rao.
Highlighted
Regular Visitor

Re: SoapUI Pro 4.5.1 - Remove empty XML elements from reques

Hi,

 

Did you got any solution for this?

Highlighted
Community Hero

Re: SoapUI Pro 4.5.1 - Remove empty XML elements from reques

@sachin123, recommend you to create a new topic with the details of the issue being faced along with sample data so that some can replicate the issue.


Regards,
Rao.
New Here?
Join us and watch the welcome video:
Top Kudoed Authors