12.1. Obtaining Commons JXPath
Problem
You need to use Jakarta Commons
JXPath
to select objects from a Collection using XPath
syntax.
Solution
You must download the latest version of Commons JXPath, and place the
Commons JXPath JAR in your
project’s classpath. Following the steps outlined in
Recipe 1.1, download Commons JXPath 1.2
instead of Commons Lang.
Discussion
Commons JXPath provides a mechanism for evaluating XML Path Language (XPath) expressions against objects and various data structures in Java. This unconventional application of XPath to objects enables a developer to traverse, address, and filter specific nodes or locations in a complex object graph. This chapter details a few of the ways in which JXPath can be used to search, select, and filter objects.
If you have a Maven project that needs to use Commons JXPath, add a
dependency on Commons JXPath 1.2 with the following section in
project.xml:
<dependencies>
<dependency>
<id>commons-jxpath</id>
<version>1.2</version>
</dependency>
....other dependencies...
</dependencies>See Also
For more information about Commons JXPath, see the Commons JXPath project page at http://jakarta.apache.org/commons/jxpath. For more information about XPath, see the official W3C XPath recommendation at http://www.w3.org/TR/xpath.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access