Creating XML using Groovy's MarkupBuilder Add comment to Wiki View in Wiki Edit Wiki page Printable Version

Simple Example

Here is an example of using Groovy's MarkupBuilder to create a new XML file:

We have used XMLUnit to compare the XML we created with our sample XML. To do this, make sure the sample XML is available, i.e. that the following class is added to your CLASSPATH:


You may also want to see Using MarkupBuilder for Agile XML creation.

DomToGroovy Example

Also, suppose we have an existing XML document and we want to automate generation of the markup without having to type it all in? We just need to use DomToGroovy as shown in the following example:

Running this will produce the builder code for us.

Namespace Aware Example

Finally, here are some simple examples showing how to include namespaces and prefixes.

Prefix with Namespace
Default Namespace



Results of your search request can come from various sources: the Groovy website itself, the JIRA issues, the API documentation, as well as a few other interesting Groovy-related blogs.

  By  -  pages  -  views  - last modified