Apache Commons logo Commons JXPath

The JXPath Component

The org.apache.commons.jxpath package defines a simple interpreter of an expression language called XPath. JXPath applies XPath expressions to graphs of objects of all kinds: JavaBeans, Maps, Servlet contexts, DOM etc, including mixtures thereof.

Consider this example:

Address address = (Address)JXPathContext.newContext(vendor).

This XPath expression is equivalent to the following Java code:

Address address = null;
Collection locations = vendor.getLocations();
Iterator it = locations.iterator();
while (it.hasNext()){
    Location location = (Location)it.next();
    String zipCode = location.getAddress().getZipCode();
    if (zipCode.equals("90210")){
      address = location.getAddress();

XPath was standardized by W3C and is used in both XSLT and XPointer.

If you want to find out more about XPath, a good place to start is an excellent XPath Tutorial by

The official definition of XPath by W3C can be found at

Primary applications of JXPath are in scripting: JSP and similar template/script based technologies. However, programmers who prefer XML-flavored APIs, should consider JXPath as an alternative to other expression languages as well. JXPath is a must-have tool for those who work with mixtures of Java objects and XML and need to frequently traverse through graphs of those.

JXPath documentation currently contains:


See the JXPath Downloads page for current/previous releases.