Wednesday, 13 February 2019

Find node from XML using Groovy Script


Find the particular node from the xml data by the below script.

GroovyScript:

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.xml.XmlUtil;
import groovy.util.*;

def Message processData(Message message) {

def body = message.getBody(java.lang.String) as String;

def xml = new XmlSlurper().parseText(body)

def x = xml.'**'.findAll { it.name() == 'claimNumber' }

body = XmlUtil.serialize(xml)

message.setProperty("claimNum",x);

message.setBody(body);

return message;

}

Call this ${property.claimNum} whereever required to retrieve the field value of ClaimNumber.


Thanks. Happy Learning!!!



No comments:

Post a Comment