SoapUI Pro 4.5.1 - Remove empty XML elements from request
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2015
09:46 AM
01-20-2015
09:46 AM
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
6 REPLIES 6
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2015
04:43 PM
01-20-2015
04:43 PM
If you are a pro user, try posting in sopaui pro boards.
Regards,
Rao.
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2015
04:47 PM
01-20-2015
04:47 PM
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.
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2015
12:40 PM
01-27-2015
12:40 PM
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>
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>
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2015
04:59 PM
01-27-2015
04:59 PM
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.
Other way build the elements only if you have the data for certain element.
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2019
08:22 AM
05-02-2019
08:22 AM
Hi,
Did you got any solution for this?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2019
08:19 PM
05-02-2019
08:19 PM
@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.
Regards,
Rao.
