Thursday 3 September 2020

Pick the xml node value and remove brackets

To pick the xml node value from the input XML which return as 

E.g: requestid => [345]

Now to remove the array brackets, also handled in script.

Now, requestid => 345 


Groovy Script:


import com.sap.gateway.ip.core.customdev.util.Message;

import java.util.HashMap;


def Message processData(Message message) {

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

def data = new XmlSlurper().parseText(body);

def requestid = data.'**'.findAll { node -> node.name() == 'request_id' }*.text();

def taskid = data.'**'.findAll { node -> node.name() == 'task_id' }*.text();

requestid= requestid.toString().replaceAll("\\[", "");
requestid= requestid.toString().replaceAll('\\]', "");

message.setProperty("requestid",requestid);

taskid= taskid.toString().replaceAll("\\[", "");
taskid= taskid.toString().replaceAll('\\]', "");

message.setProperty("taskid",taskid);

return message;
}



No comments:

Post a Comment