Tuesday, 8 August 2023

Remove XML hierarchy (multiple levels)nodes from the xml



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)

xml.Lines.SerialNumber.Sub_Component.children().findAll { it.name() == 'SubCompDescription' }.replaceNode {}


xml.Lines.SerialNumber.children().findAll { it.name() == 'ItemDescription' }.replaceNode {}

body = XmlUtil.serialize(xml)

message.setBody(body);

return message;

}







No comments:

Post a Comment