Chapter 17Groovy Builders

Builders are internal DSLs that provide ease in working with certain types of problems. For instance, if we need to work with nested, hierarchical structures, such as tree structures, XML, HTML, or JavaScript Object Notation (JSON) representations, we’ll find builders to be very useful. They provide syntax that does not tie us tightly to the underlying structure or implementation. They don’t replace the underlying implementation; instead, they provide an elegant way to work with it.

We can use Groovy builders for a number of everyday tasks, including working with XML, JSON, HTML, DOM, SAX, Swing, and even Ant. In this chapter we’ll look at a few tasks to get a feel for builders. We’ll then explore two techniques ...

Get Programming Groovy 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.