Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using MarkupBuilder to generate html markup in groovy
// MarkupBuilder is a lot cleaner way of generating valid xml/html markup
// than writing tags as string and forgetting to close one ;)
def writer = new StringWriter() // html is written here by markup builder
def markup = new groovy.xml.MarkupBuilder(writer) // the builder
markup.html{
table {
tr {
td(class:"row", "hello world!")
}
}
}
println writer.toString()
/* produces output :
<html>
<table>
<tr>
<td>hello world!</td>
</tr>
</table>
</html>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.