I’ve the following closure:
def myData = {
mkp.xmlDeclaration()
OneEntry() {
SecondInnerEntry()
}
}
I can serialize its XML representation with StreamingMarkupBuilder (import omitted):
System.out << XmlUtil.serialize(new StreamingMarkupBuilder().bind(myData))
Which give me:
<?xml version="1.0" encoding="UTF-8"?>
<OneEntry>
<SecondInnerEntry/>
</OneEntry>
But now i want to add a new entry before calling the bind() method of StreamingMarkupBuilder to obtain:
<?xml version="1.0" encoding="UTF-8"?>
<OneEntry>
<FirstInnerEntry/>
<SecondInnerEntry/>
</OneEntry>
How can i do this (i.e manipulate the closure to insert a new node, I don’t want to recreate the whole myData to just insert one element) ?
Without changing
myData(as erimerturk says), or performing two passes, ie:myDataXmlParserI don’t think this is possible.. The question boils down to:
To which the simple answer is “You can’t”*
(* it might be possible to do what you are trying by means of an AST Transformation, but I get the feeling it may not be possible in this case)