I have the same requirement enter link description here, groovy script gives me expected JSON output. I also have some date fields in XML which i need to format from dd-mm-yyyy to yyyy-mm-dd. I don't know how to format with my groovy script.
def inputXml = message.getBody(String.class);
def parsed = new XmlSlurper().parseText(inputXml);
def values = ['Rows' : parsed.'**'.findAll { it.name() == 'row' }.collect { element -> [Values: element.'**'.findAll { !it.childNodes() }*.text()] }]
def fields = ['Columns': parsed.'**'.find { it.name() == 'row' }.collectMany { element -> element.'**'.findAll { !it.childNodes() }*.name() }]
fields += values;
def outputJson = new groovy.json.JsonBuilder(fields).toPrettyString();
message.setBody(outputJson);
working with below code -