Forum Discussion

deepthireddy's avatar
deepthireddy
New Contributor
5 years ago

Groovy SCript for taking specific tag values into getDOMNodes

I have below response from SOAP UI

<m:bansArray>
<m:item>
<m:ban>4382640110 056</m:ban>
<m:banNickname></m:banNickname>
<m:billingAddressLine1>10500 RYAN</m:billingAddressLine1>
<m:billingAddressLine2>DORVAL QC</m:billingAddressLine2>
<m:billingName>DICOM TRANSPORTATION</m:billingName>
<m:billingPostalCode>H9P2T7</m:billingPostalCode>
<m:idrCustomerAccountId>506757</m:idrCustomerAccountId>
<m:invoiceSystemCode>CBSS</m:invoiceSystemCode>
<m:marketSegment>B</m:marketSegment>
<m:paperSuppressionFlag>Y</m:paperSuppressionFlag>
<m:serviceCode>CBSS</m:serviceCode>
<m:serviceCodeEnglishDescription>Phone</m:serviceCodeEnglishDescription>
<m:serviceCodeFrenchDescription>Téléphonie</m:serviceCodeFrenchDescription>
<m:transpromoStatus>A</m:transpromoStatus>
</m:item>
</m:bansArray>

 

I dont want to take the node values of serviceCodeEnglishDescription, serviceCodeFrenchDescription and transpromoStatus

 

I have written below Groovy scripting it is taking all the Node values

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

def holder = groovyUtils.getXmlHolder( "SOAP Request#Response" )

def nodes = holder.getDomNodes( "//*" );

def XMLlist = []

for( node in nodes )
{


def value = com.eviware.soapui.support.xml.XmlUtils.getNodeValue( node )
if((value!=null))
{
if(!(value.isAllWhitespace()))
{
XMLlist.add(value)
}
}

}
def Slist = XMLlist.size()

log.info "SOAP UI RESPONSE" + XMLlist

Here in my SOAP UI REsponse im getting all node values

SOAP UI RESPONSE[4382640110 056, 10500 RYAN, DORVAL QC, DICOM TRANSPORTATION, H9P2T7, 506757, CBSS, B, Y, CBSS, Phone, Téléphonie, A]

 

But i dont want all tags in SOAP UI RESPONSE.

could you please help

 

  • Hi deepthireddy :

     

    Hope you will get help from below code 🙂

     

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    
    def holder = groovyUtils.getXmlHolder( "SOAP Request#Response" )
    
    def nodes = holder.getDomNodes( "//*" )
    
    def XMLlist = []
    
    for( node in nodes )
    {
    	if(!(node.getNodeName().toString().contains("m:serviceCodeEnglishDescription")  || node.getNodeName().contains("m:serviceCodeFrenchDescription") || node.getNodeName().contains("m:transpromoStatus")) ){
    		def value = com.eviware.soapui.support.xml.XmlUtils.getNodeValue( node )
    		if((value!=null))
    		{
    			if( !(value.isAllWhitespace()))
    				XMLlist.add(value)
    		}
    	}
    }
    def Slist = XMLlist.size()
    log.info "SOAP UI RESPONSE" + XMLlist
  • Hi deepthireddy :

     

    Hope you will get help from below code 🙂

     

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    
    def holder = groovyUtils.getXmlHolder( "SOAP Request#Response" )
    
    def nodes = holder.getDomNodes( "//*" )
    
    def XMLlist = []
    
    for( node in nodes )
    {
    	if(!(node.getNodeName().toString().contains("m:serviceCodeEnglishDescription")  || node.getNodeName().contains("m:serviceCodeFrenchDescription") || node.getNodeName().contains("m:transpromoStatus")) ){
    		def value = com.eviware.soapui.support.xml.XmlUtils.getNodeValue( node )
    		if((value!=null))
    		{
    			if( !(value.isAllWhitespace()))
    				XMLlist.add(value)
    		}
    	}
    }
    def Slist = XMLlist.size()
    log.info "SOAP UI RESPONSE" + XMLlist