I have an issue where I'm trying to dynamically create nested xml nodes in groovy. When I say dynamic, I mean using a StringTokenizer, so passing in a string "a.b", would give be a node like this:
<a>
<b></b>
</a>
I already have the following code that can create a node with values and attributes (using a MarkupBuilder and StringWriter)
"${node.node_name}"(node.attributes, node.value);
If I were to replace this with
a{b()}
That would give be a nested node, but I need to create the node dynamically. I'm guessing that I'd use a StringTokenizer and do something like this
while(tokenizer.hasMoreElements()) {
final String nodeName = tokenizer.nextToken();
if(tokenizer.hasMoreElements()) {
// create child node
} else {
// add value and attribute to final nested node
"${nodeName}"(node.attributes, node.value);
}
}
Thanks for any help.