public static void writeSlurperResult(GPathResult result, Writer output) throws IOException {
Binding b = new Binding();
b.setVariable("node", result);
// this code takes the XML parsed by XmlSlurper and writes it out using StreamingMarkupBuilder
// don't ask me how it works, refer to John Wilson ;-)
Writable w = (Writable)new GroovyShell(b).evaluate(
"new groovy.xml.StreamingMarkupBuilder().bind {" +
" mkp.declareNamespace(\"\": \"http://java.sun.com/xml/ns/j2ee\");" +
" mkp.yield node}");
w.writeTo(output);
}