import groovy.xml.XmlSlurper
import groovy.xml.XmlUtil


//XmlSlurper (boolean validating, boolean namespaceAware)
var rootNode = new XmlSlurper(false, true).parseText(responseBodyTextToClient).declareNamespace('soapenv':'http://schemas.xmlsoap.org/soap/envelope/' , 'ns1':'http://url/services/method/' )

//soapEnv: Envelope is the main object
def element=rootNode.'soapenv:Body'.'ns1:mainValue'.'ns1:childValue'

if(element == ''){
//If the field has no value, deletes the node
rootNode.'soapenv:Body'.'ns1:mainValue'.'ns1:childValue'.replaceNode { }
}
else if (element.text().size() == 1){
//If the length of the value in the field is 1, it adds two leading zeros.
rootNode.'soapenv:Body'.'ns1:mainValue'.'ns1:childValue'.replaceBody('00'+element.text())
}

responseBodyTextToClient = XmlUtil.serialize(rootNode)
GROOVY