I need to build a tree structure in xml where child element can have another child inside. Number of nested nodes is not specified. So I am using StreamingMarkupBuilder :
def rootNode = ....
def xml = builder.bind {
"root"(type:"tree", version:"1.0") {
type(rootNode.type)
label(rootNode.label)
"child-components" {
rootUse.components.each { comp ->
addChildComponent(comp,xml)
}
}
}
But I have problem creating proper addChildComponent method. Any ideas ?
Edit : Ok I made it so :
def addChildComponent {comp,xml ->
xml.zzz(){
"lala"()
}
}
but now I have problem with namespaces as I get :
<child-components>
<xml:zzz>
<lala/>
</xml:zzz>
<xml:zzz>
<lala/>
</xml:zzz>
<xml:zzz>
<lala/>
</xml:zzz>
</child-components>
thx
Your Closure
addChildComponentis still wrong in this case.Instad of passing “xml” (second) parameter to closure, you should set delegate to “parent” closure.
Example:
Output:
Hope you’ll find this helpful.