Grails Cookbook - A collection of tutorials and examples

Groovy Create XML Document Examples

In previous examples, we show how to parse XML documents using XmlSlurper and XmlParser. This post will show the opposite. We give examples on how to create XML documents.

Groovy XmlParser Examples for Parsing XML

Parsing XML information is common to many projects. We showed int he previous post on how to parse XML documents using XmlSlurper. This post will focus on giving examples on how to parse documents using XmlParser.

Groovy XmlSlurper Examples for Parsing XML

One common task in an enterprise application is parsing of XML documents. This task is commonly complicated in Java with lots of plumbing code, but is fairly easy and straightforward in Groovy. Below are examples on how to parse XML in Groovy using XmlSlurper. Visit this post if you wish to parse XML using XmlParser.

Groovy Switch Statement Examples

The Switch statement in Groovy is more powerful than in Java. There are things that are easy to do in Groovy switch statements that are not available in Java. It is also more concise and easier to read. Below are several examples on how to use Groovy switch statements.

Groovy List Tutorial And Examples

A list is a common data structure that is used to store a collection of data. This can be used to store varying amount of data where the number of items is only determined at run time. Or it can also be used to store large amount of data where having different variables for each is not practical. Below are examples on how to use and manipulate List in Groovy.

Groovy Substring Examples

Getting a substring from another String is one of the basic building blocks of String manipulation. Most programming languages supports it out of the box. In Groovy, there are some cool ways of how to perform this operation. Below are some examples on different ways of getting substrings in Groovy.

Groovy Add To Map Examples

Maps are very useful in programming. It can be used to cache results of expensive operations to help improve performance. One of the basic operation in maps is how to add entries to it. Below are some examples on how to Add or put values to a map in Groovy.

Groovy Array Length

Array manipulation is common in any programming language. Here is a sample code on how to get the the length of an array in Groovy.

Groovy Copy File Examples

When writing batch programs, it is common to write code to copy files from one directory to another. Here are examples on how to Copy Files in Groovy.

Groovy FindAll

Groovy is popular for writing short and concise codes. Programs that contains many lines of code using Java can be shortened in Groovy. This greatly helps in developer productivity. A feature that is commonly used in Groovy is in searching for items in a collection. The Groovy FindAll method searches for a subset of a collection that matches a given criteria. Here are some examples on how to use Groovy FindAll: