XPath API for Java
This section describes how to use Saxon as a Java class library for XPath processing, without making any use of XSLT stylesheets. It includes information on the XPath API, and the API for the Saxon implementation of the XPath object model. On other pages you will find the API for XSLT transformation, the API for running XQuery, and the API for Schema validation.
For information about the different ways of loading source documents, see Handling Source Documents.
Saxon supports three Java APIs for XPath processing, as follows:
-
The preferred interface for XPath processing is Saxon's s9api interface ("snappy"), which also supports XSLT and XQuery processing, schema validation, and other Saxon functionality in an integrated set of interfaces. This is described at Evaluating XPath Expressions using s9api.
-
The JAXP API is a (supposedly) standard API defined in Java 5. Saxon implements this interface. Details of Saxon's implementation are described at JAXP XPath API. Note that there are some extensions and other variations in the Saxon implementation. Some of the extensions to this interface are provided because Saxon supports XPath 2.0 (and higher), whereas JAXP 1.3 is designed primarily for XPath 1.0; some are provided because Saxon supports multiple object models, not only DOM; some are for backwards compatibility; and some are provided to allow applications a finer level of control if required.
-
For historical reasons Saxon continues to support a legacy XPath API in package
net.sf.saxon.sxpath
. This is documented only in the Javadoc specifications. It is a lower-level API, so as well as being retained for backwards compatibility, it may also be appropriate for applications that require a very intimate level of integration with Saxon internals.
Saxon allows XPath expressions to be evaluated either against its own native tree models of XML (the tiny tree and linked tree), and also against trees built using the DOM, JDOM, JDOM2, DOM4J, XOM, or AXIOM tree models. (It's also possible to build adapters for other tree models, though this is not for the faint-hearted.)