0
生成格式良好的XML我有一個生成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)
然而,在打印此XML時,一個簡單的Groovy腳本......它在一個行打印的一切。所以輸出是:
<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>