Skip to content

Instantly share code, notes, and snippets.

@jpertino
Created December 6, 2010 22:30
Show Gist options
  • Save jpertino/731105 to your computer and use it in GitHub Desktop.
Save jpertino/731105 to your computer and use it in GitHub Desktop.
groovy xml string generation
def referenceClosure = {
html {
body {
h1 "hello"
}
}
}
def markupBuilder(closure) {
new StringWriter().with{new groovy.xml.MarkupBuilder(it).with(closure); it.toString()}
}
def streamingMarkupBuilder(closure) {
new groovy.xml.StreamingMarkupBuilder().bind(closure).toString()
}
def prettyStreamingMarkupBuilder(closure) {
groovy.xml.XmlUtil.serialize(new groovy.xml.StreamingMarkupBuilder().bind(closure))
}
println markupBuilder(referenceClosure)
println streamingMarkupBuilder(referenceClosure)
println prettyStreamingMarkupBuilder(referenceClosure)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment