By entering the name of the parent node you want to filter in the XML into the “nodeName” field, you can dynamically convert the relevant node and all its child nodes to JSON.

The Rest-2-Soap feature on Apinizer can be used to expose an XML/SOAP web service as JSON/REST. For detailed information, please refer to the Opening a Legacy SOAP Web Service as a REST AP

The following code sample demonstrates a scenario where an XML request is processed on the request line. If you intend to apply the same conversion script on the response line, use the responseBodyTextToClient variable instead of requestBodyTextFromClient

import groovy.util.XmlSlurper
import groovy.json.JsonOutput

try {
    def slurper = new XmlSlurper(false, false)
    def data = slurper.parseText(requestBodyTextFromClient)

    def parsedData = data.'**'.findAll { it.name().contains('nodeName') }

    def result = [:]

    parsedData.each { node ->
        node.'**'.each { subNode ->
            if (!subNode.children() || subNode.children().size() == 0) {
                result[subNode.name()] = subNode.text()
            }
        }
    }

    requestBodyTextFromClient = JsonOutput.prettyPrint(JsonOutput.toJson(result))
} catch (Exception ex) {
    requestErrorMessageToTargetAPI = ex.message
}

GROOVY