I have a simple groovy script that generates xml
def builder = new groovy.xml.StreamingMarkupBuilder()
def person1 = {
person(id:99){
firstname("John" )
lastname("Smith" )
}
}
def person2 = {
person(id:100){
firstname("Jane" )
lastname("Doe" )
}
}
def personList = {
"person-list" {
out << person1
out << person2
}
}
println builder.bind(personList)
However, when this xml is printed...it prints everything in one line. So output is:
<person-list><person id='99'>test</person><person id='100'><firstname>Jane</firstname><lastname>Doe</lastname></person></person-list>
Is there a way to print this in a well formatted manner like the following?
<person-list>
<person id='99' >
<firstname>John</firstname>
<lastname>Smith</lastname>
</person>
<person id='100' >
<firstname>Jane</firstname>
<lastname>Doe</lastname>
</person>
</person-list>