Chapter 5. Working with XML in Groovy

In this chapter, we will cover the following recipes:

  • Reading XML using XmlSlurper
  • Reading XML using XmlParser
  • Reading XML content with namespaces
  • Searching in XML with GPath
  • Searching in XML with XPath
  • Constructing XML content
  • Modifying XML content
  • Sorting XML nodes
  • Serializing Groovy Beans to XML

Introduction

Dealing with XML in Java is notoriously a tedious business. The Java architects traded flexibility for simplicity, and the Java XML APIs are considered among the lower peaks of the language. Fortunately, Groovy offers a marvelous alternative for reading and producing XML. It's so good that once you experience Groovy's native parsers and emitters, you'll wonder why you used anything else.

This chapter is divided into recipes that deal with reading XML and producing XML. The two Groovy parsers, XmlParser and XmlSlurper, are discussed in detail as well as the two XML producers, MarkupBuilder and StreamingMarkupBuilder. We also touch on advanced topics such as the serialization of Java and Groovy objects to XML, and element tree navigation with XPath and GPath.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.29.119