Creating XML

When creating business applications, we often have a number of reasons to present data in XML format—as a way to store the state of an application, to communicate with web services, to represent some configuration data, and so on. Whatever the need, Groovy makes it quite easy to create XML documents.

We can use the full power of Java APIs to generate XML. If we have a particular favorite Java-based XML processor, such as Xerces, we can use it with Groovy as well.[28] This might be a good approach if we already have working code in Java to create XML documents in a specific format and want to use it in our Groovy projects.

If we want to create an XML document using a pure-Groovy approach, we can use GString’s ability to embed ...

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.