Appendix C. XML and Spring builders

Groovy allows you to easily generate XML using the groovy.xml.MarkupBuilder class. We’ll show you the basic mechanics of that class and then look at how Spring’s XML configuration format maps to the bean builder syntax used in chapter 14, because the mapping is similar.

C.1. XML generation with MarkupBuilder

Generating XML text is trivial with the MarkupBuilder class. We’ll demonstrate with a simple example, as shown in the following listing.

Listing C.1. Using MarkupBuilder to generate XML text

This will create the file test.xml containing the content, shown in the following listing.

Listing C.2. Creating ...

Get Grails in Action, Second Edition 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.