Groovy web console

subscribe to the feed Subscribe
to this

Convert dynamic XML rows to JSON key value pairs 3

Published 4 weeks ago by Anonymous
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def xml = "<clients><client><clientId>00001</clientId><name>Client 1</name><timeUDFLinks><u1t>UDF1</u1t><w3t>UDF3</w3t><u7t>UDF7</u7t></timeUDFLinks></client></clients>"
def parsed = new XmlSlurper().parseText(xml)
def map = parsed.'*'.timeUDFLinks.'*'.collectEntries{row -> [, row.text()]}
println new groovy.json.JsonBuilder(map).toPrettyString()