Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 17 Next »

Processing existing XML

Groovy provides special XML processing support through the following classes:

Technology

When/Why to use

Requirements

XmlParser

supports GPath expressions for XML documents and allows updating

-

XmlSlurper

lower overheads than XmlParser due to lazy evaluation but only supports read operations

-

If you have special needs, you can use one of the many available Java APIs for XML processing:

Technology

When/Why to use

Requirements

DOM

low-level tree-based processing

-

DOM using Groovy's DOMCategory

low-level tree-based processing where you want some syntactic sugar

place use(DOMCategory) around your code

SAX

event-based push-style parsing can be useful for streaming large files

-

StAX

event-based pull-style parsing can be useful for streaming large files

requires stax.jar

DOM4J

nicer syntax over DOM processing plus can be useful for large files if you use prune capability

requires dom4j.jar

XOM

nicer syntax over DOM processing plus a strong emphasis on compliancy

requires xom.jar

JDOM

nicer syntax over DOM processing

requires jdom.jar

XPath

use XPath expressions

-

Jaxen

use XPath expressions with slightly more efficiency than built-in XPath

requires jaxen.jar

For some more discussion of the pro's and con's of your XML Processing options and some additional details, see Chapter 12 of GINA.

Creating new XML

The most used Groovy technique is to use one of:

Technology

When/Why to use

Requirements

StreamingMarkupWriter

for larger files

-

MarkupBuilder

supports Groovy's builder pattern with XML/HTML

-

You can also use XmlParser, DOM, DOM with category support, DOM4J, JDOM.

More Information

See also:

  • Groovy SOAP
  • Testing Web Services
  • Testing Web Applications
  • No labels