Skip to Content

Change data of a child node in message payload using a content modifier property using groovy script

Hi Experts,

Can you please help me out in these scenario of the subject mentioned as am new to HCI.

I have created like these below:

In the First Content Modifier i have used like these in the body:

<?xml version="1.0" encoding="UTF-8"?>
<city>New Hyde Park</city>
<businessPhone>(1) 215 555-0922</businessPhone>
<addressLine1>11 Lightner Ave</addressLine1>

And in the second Modifier

And in the Groovy Script i have written these code:

import java.util.HashMap;
import java.util.HashMap;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;

def Message processData(Message message)
def body = message.getBody();
def map = message.getHeaders();

//get the constant value associated with header 'id'
def value = map.get("id");

SAXBuilder builder = new SAXBuilder();
Document doc =;

Element compoundEmployeeList = doc.getRootElement();
List<Element> User = compoundEmployeeList.getChildren("User");

for(Element cEmployee : User)
// Extract the external id for the current employee

Element person = cEmployee.getChild("Item");


//Write your logic here
message.setProperty("payload", new XMLOutputter().outputString(doc));

return message;

Kindly help me to get through these scenario.


az4xi.png (17.0 kB)
hbayx.png (14.8 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    May 16, 2018 at 02:20 PM

    Hi Raju

    The following Groovy script does three things:

    1. It parses the input XML using the groovy.util.XmlSlurper class
    2. It sets the text of the queryUserResponse/User/Item element to the contents of the id property
    3. It serializes the updated document using groovy.xml.XmlUtil and stores it in the message body

    Here's the script:

    import groovy.util.XmlSlurper
    import groovy.xml.XmlUtil
    def Message processData(Message message) {
        def itemNewVal = message.getProperty('id')
        def queryUserResponse = new XmlSlurper().parseText(message.getBody(java.lang.String))
        return message



    Add comment
    10|10000 characters needed characters exceeded