如何在Groovy中创建XML?
def xml = new groovy.xml.MarkupBuilder()
xml.langs(type:"current"){
language("Java")
language("Groovy")
language("JavaScript")
}
是的,我知道,它有效.. 但我需要这样的XML:
<root>
<one param="var">
<some param="var">variable</some>
<some param="var">variable</some>
...
</one>
<two>
<some param="var">variable</some>
<some param="var">variable</some>
<some param="var">variable</some>
...
</two>
...
</root>
我将循环循环。 Inner for和outer for,...但是如何将其添加到XML?
谢谢!
答案 0 :(得分:2)
这样的事情开头?
def outerLoop = ['one', 'two', 'three', 'four']
def innerLoop = ['a', 'b']
def xml = new groovy.xml.MarkupBuilder()
xml.root {
outerLoop.each { outer ->
xml."$outer"(param: 'var') {
innerLoop.each { inner ->
xml."$inner"(params: 'abc', "value")
}
}
}
}