Skip to content

Instantly share code, notes, and snippets.

@kdabir
Last active September 15, 2020 05:15
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kdabir/1885146 to your computer and use it in GitHub Desktop.
Save kdabir/1885146 to your computer and use it in GitHub Desktop.
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