Groovy web console

subscribe to the feed Subscribe
to this
site
test (via #groovywebconsole)
tweet this snippet Tweet
this
script

test

Published 2 months ago by kv with tags 1 1
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
private String toXml(Closure closure) { 
List<Object[]> rows = GroovyTables.createListOfArrays(closure)     
Iterator<Object[]> rowsIterator = rows.iterator()     
Object[] headingRow = rowsIterator.next()     
StringBuilder sb = new StringBuilder()     
while (rowsIterator.hasNext()) {         
Object[] row = rowsIterator.next()         
sb.append("<row>\n")         
for (int i = 0; i < row.length; i++) {             
sb.append(" <${headingRow[i].name}>${row[i]}</${headingRow[i].name}>\n")    }         
sb.append("</row>\n")     }     
return sb.toString() }