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 »

GPath is a path expression language we've integrated into Groovy which is similar in aims and scope as XPath is to XML.
1. Expression language for tree structured data
2. Implementations for XML
3. Can specify a path to an element
a.b.c -> all the <c> elements inside <b> inside <a>
4. Can specify attributes
a["@href"] -> the href attribute of all the a elements
a.@href -> an alternative way of expressing this

Example

The best example of GPath for xml is test-new/groovy/util/XmlSlurperTest.groovy.

Outline

1.Accessing element as property
2.Accessing attributes
3.Accessing element body

If the element is a father node,it will print all children's text.

3.Explore the DOM use children() and parent()
4.Find elements use expression

Another Example

Here is a two line example of how to get a list of all the links to .xml files listed on a web page. The Neko parser is used to parse non-well formed html; it ships as part of the standard Groovy distribution.

References

Error rendering macro 'link' : Link needs a name and a URL as arguments.
by Jack Herrington.

  • No labels