我有一个生成xml的简单groovy脚本
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)
然而,当打印这个xml时......它会在一行中打印所有内容。所以输出是:
<person-list><person id='99'>test</person><person id='100'><firstname>Jane</firstname><lastname>Doe</lastname></person></person-list>
有没有办法以格式良好的方式打印出来,如下所示?
<person-list>
<person id='99' >
<firstname>John</firstname>
<lastname>Smith</lastname>
</person>
<person id='100' >
<firstname>Jane</firstname>
<lastname>Doe</lastname>
</person>
</person-list>