JXPath Home – Apache Commons JXPath
Apache Commons JXPath ™
Last Published: 13 Apr 2025
Version: 1.4.0
ApacheCon
Apache
Commons
Commons JXPath
About
Asking Questions
Release History
Issue Tracking
Dependency Management
Sources
Security
License
Code of Conduct
Javadoc
Javadoc Current
Javadoc Archive
User's Guide
Wiki
Building
Release Notes 1.1
Release Notes 1.2
Release Notes 1.3
Project Documentation
Project Information
About
Summary
Team
Source Code Management
Issue Management
Mailing Lists
Maven Coordinates
Dependency Management
Dependencies
Dependency Convergence
CI Management
Distribution Management
Project Reports
Commons
License
Components
Sandbox
Dormant
General Information
Security
Volunteering
Contributing Patches
Building Components
Commons Parent POM
Commons Build Plugin
Commons Release Plugin
Site Publication
Releasing Components
Wiki
ASF
How the ASF works
Get Involved
Developer Resources
Code of Conduct
Sponsorship
Thanks
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).
getValue("locations[address/zipCode='90210']/address");
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();
break;
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
W3Schools
The official definition of XPath by W3C can be found at
XML Path Language (XPath) Version 1.0
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.
Some XPath expressions may cause Java code execution, so you should not allow arbitrary expressions from untrusted input,
which could in turn lead to security issues in your environment. Future enhancements may include the addition of an allow
list to let developers provide a stricter execution environment for expressions.
JXPath documentation currently contains:
User's Guide
Javadoc API Documentation
Releases
See the
JXPath Downloads
page for current/previous releases.
Copyright © 2001-2025
The Apache Software Foundation