Groovy web console

subscribe to the feed Subscribe
to this
site

CheckifTagisNull and do any operation

Published 5 months ago by KALDUR with tags find isEmpty Null null XML slurper
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import groovy.xml.*
def payload = '''<Root>    
<Compund> 
<Employee>   
<EMP>    
<User>    
<ID>1000</ID>    
</User>    
<Address>    
<City>Kolkata</City>    
<Pin>70001</Pin>    
</Address>  
</EMP>    
<EMP>    
<User>    
<ID>1001</ID>    
</User>    
</EMP> 
<EMP>    
<User>    
<ID>1009</ID>    
</User> 
<Address>        
</Address> 
</EMP>
<EMP>    
<User>    
<ID>1002</ID>    
</User>    
<Address>    
<City>Hyderabad</City>    
<Pin>700136</Pin>    
</Address>    
</EMP>   
</Employee> 
</Compund>    
</Root>
'''
def parse1 = new XmlSlurper().parseText(payload)
def len1 = parse1.Compund.Employee.EMP.size()

for(int i=0;i<len1;i++){
def check = parse1.Compund.Employee.EMP[i].Address

if(check.find() == null){
parse1.Compund.Employee.EMP[i].appendNode{
  
    Address{
         
       City ('done')
    
}

}

}

}
XmlUtil.serialize(parse1)