import groovy.xml.XmlSlurper
import groovy.xml.XmlUtil
// Parse XML
def parsedXml = new XmlSlurper().parseText(requestBodyTextFromClient)
// Find the first element in the body
def methodNode = parsedXml.'**'.find { it.parent().name() == 'Body' }
// Check if the <ELEMENT_NAME> element is present in the children element in the body
def <ELEMENT_NAME>Node = methodNode.children().find { it.name() == '<ELEMENT_NAME>' }
// If there is no <ELEMENT_NAME> element, it is inserted into the child element in the body
if (!wsInfoNode) {
methodNode.appendNode {
<ELEMENT_NAME>(' ')
}
}
// XML is serialized.
requestBodyTextToTargetAPI = XmlUtil.serialize(parsedXml)
GROOVY