Forum Discussion

subex's avatar
subex
Occasional Contributor
10 years ago

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

  • nmrao's avatar
    nmrao
    Champion Level 3
    If you are a pro user, try posting in sopaui pro boards.
  • nmrao's avatar
    nmrao
    Champion Level 3
    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?
  • subex's avatar
    subex
    Occasional Contributor
    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>
      • nmrao's avatar
        nmrao
        Champion Level 3
        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.
  • nmrao's avatar
    nmrao
    Champion Level 3
    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.