Forum Discussion

pbmca27's avatar
pbmca27
New Contributor
6 years ago

How to dynamically remove empty node from request xml in ReadyAPI?

Hello

 

I have 

1. A Data source with 2 columns (firstName, lastName) with a row of data

2. In one row the firstName is empty

3. I have a SOAP test with the Properties from the Excel mapped

 

Now everytime the row with missing firstName is hit, it is introducing <firstName></firstName> in the request XML (which can only be seen from Raw view. XML view does not comntain the empty tag since I modified the SoapTest Property "RemoveEmptyContent" to true) and the response fails (since there is a rule that any of these firstName, lastName should either do not have values or value of length 1 - 10).

 

So the Request XML I am expecting is

 

<customerSearchRequest xmlns="http://www.XYZ.net/services/customersearch">
<customerName> 
<lastName>Langley</lastName>
</customerName> 
</customerSearchRequest>

 

but it is taking 

 

<customerSearchRequest xmlns="http://www.XYZ.net/services/customersearch">
<customerName> 

<firstName></firstName>
<lastName>Langley</lastName>
</customerName> 
</customerSearchRequest>

 

I followed the post and created a RequestFilter.filterRequest event and wrote the below code in the Edit section (I am using ReadyAPI)

 

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def stepName = context.getCurrentStep().getLabel()

def holder = groovyUtils.getXmlHolder(stepName + "#Request")

 

for( item in holder.getDomNodes( "//*[. = '']" )){
holder.removeDomNodes("//"+item.nodeName)
}

holder.updateProperty()

context.requestContent = holder.xml

But I am unable to remove <firstName></firstName> from the request. Where am I doing wrong? 

No RepliesBe the first to reply