> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apinizer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Parsing SOAP Message with XmlSlurper and Manipulating Fields

> Parsing SOAP message with Groovy script and manipulating fields, value checking and changing operations

## Groovy Script

```groovy theme={null}
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:anaDeger'.'ns1:altDeger'

if(element == ''){
  //Deletes node if field value is empty
  rootNode.'soapenv:Body'.'ns1:anaDeger'.'ns1:altDeger'.replaceNode { }
} else if (element.text().size() == 1){
  //If value length in field is 1, adds two zeros at the beginning
  rootNode.'soapenv:Body'.'ns1:anaDeger'.'ns1:altDeger'.replaceBody('00'+element.text())
}

responseBodyTextToClient = XmlUtil.serialize(rootNode)
```

## Explanation

This script performs the following operations:

1. **XML Parse**: SOAP message coming from response body is parsed
2. **Element Check**: Value of specified element is checked
3. **Node Deletion**: If element is empty, node is deleted
4. **Value Change**: If element value is 1 character, "00" is added at the beginning
5. **XML Serialize**: Updated XML is serialized

<Note>
  This script should be run on the response line (Response Policy) because it uses the `responseBodyTextToClient` variable.
</Note>
