Groovy for Domain-specific Languages - Second Edition

(nextflipdebug2) #1
Chapter 7

[ 153 ]

}
body {
h1 "Groovy Builders are cool!"
}
}

then:
xmlIsIdentical writer.toString(), "simple.html"

In the next example, we build a more complex HTML page containing nested tables.
MarkupBuilder will close all tags correctly so that they are well-formed. A classic
mistake when working with nested tag formats is to misplace or unbalance the
closing of tags. The HTML

tag and its nested and
tags are
highly prone to error when hand-coded. Assume that we want to generate HTML to
display the names of the various Groovy builder and ConcreteBuilder classes in a
nested table.


The HTML to produce this table would be something like the following:


<html>
<head>
<title>Groovy Builders</title>
</head>
<body>
<table style='border: 1px solid black;'>
<tr>
<th>Builder class</th>
<th>Concrete class</th>
</tr>
<tr>
<td>groovy.util.BuilderSupport</td>
<td>
<table>
<tr>
<td>groovy.util.AntBuilder</td>
</tr>
<tr>
<td>groovy.xml.MarkupBuilder</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>groovy.util.FactoryBuilderSupport</td>
<td>