I call some cloud that allows to execute groovy scripts.
I return data as xml from this scripts.
I use code like this:
def writer;
def xml;
writer = new StringWriter();
xml = new MarkupBuilder(writer);
xml.Response() {
node('arrtibute1': value4arrtibute1);
}
But I need to use more sophisticated way to calculating values. I want to put a lot of different nodes in this.
def writer;
def xml;
writer = new StringWriter();
xml = new MarkupBuilder(writer);
xml.Response() {
Function1();
Function2();
}
…
and implementations of this functions.
public void Function1(){
node1('arrtibute1': value4arrtibute1);
}
public void Function2(){
someOtherNode1('arrtibute1': otherValue4arrtibute1, ...);
}
Latest code doesn’t work. The reason why it doesn’t work is functions don’t know that they run in context of response and looking for methods node1 and someOtherNode1.
When I try to pass xml in functions and try to create new response there I have deformed structure of xml document (document in document).
My question: how to let code in function to “know” that they are run in context of response?
You need to pass the builder into the functions you are calling like so: