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 5 Next »

Car Example

This example assumes the following class is already on your CLASSPATH:

XmlExamples.groovy

Here is an example of using XPath with Groovy to read an existing XML file:

If you are using Java 5 and above, you don't need to use the standalone Xalan jar but instead can use the built-in XPath facilities:

People in Groups Example

Inspired by this example here is how to use XPath to determine which groups include all three of alan, paul and ivan for this graph.


Picture source: http://stage.vambenepe.com/pages/graph.png

First, here is the data:

Here is how to check that groups 2 and 4 are the groups in question:

Of course, you can also do this using Groovy's XML facilities as follows:

  • No labels