Groovy web console

subscribe to the feed Subscribe
to this
site
Markup builder with variable (via #groovywebconsole)
tweet this snippet Tweet
this
script

Markup builder with variable

Published 3 months ago by Phoenix with tags Groovy MarkupBuilder
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import org.custommonkey.xmlunit.*
import groovy.xml.*

def param = [root:[userlist:[user1:[user:'1',rest:'2',name:'3'],sub:[user2:[user3:'4']],sub2:[user4:[user5:'5']]],userlist1:[user1:[user:'1',rest:'2',name:'3'],sub:[user2:[user3:'4']],sub2:[user4:[user5:'5']]]]]

String output = new groovy.xml.StreamingMarkupBuilder().bind {
    param.each { k, v ->
        "$k" { v instanceof Map ? v.each( owner ) : mkp.yield( v ) }
    }
}

XmlUtil.serialize(output)