Created
December 6, 2010 22:30
-
-
Save jpertino/731105 to your computer and use it in GitHub Desktop.
groovy xml string generation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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