public class XPathEvaluator
extends java.lang.Object
implements javax.xml.xpath.XPath
XPathEvaluator implements the JAXP API for standalone XPath processing (that is, executing XPath expressions in the absence of an XSLT stylesheet). It is an implementation of the JAXP 1.3 XPath interface, with additional methods provided (a) for backwards compatibility (b) to give extra control over the XPath evaluation, and (c) to support XPath 2.0.
It is intended to evolve this so that it only supports the JAXP style of operation. Some of the methods are therefore marked as deprecated in this release, and will be dropped in a future release.
For an alternative XPath API, offering more direct access to Saxon capabilities,
see XPathEvaluator
.
Note that the XPathEvaluator
links to a Saxon Configuration
object. By default a new Configuration
is created automatically. In many
applications, however, it is desirable to share a configuration. The default configuration
is not schema aware. All source documents used by XPath expressions under this evaluator
must themselves be built using the Configuration
used by this evaluator.
Constructor and Description |
---|
XPathEvaluator()
Default constructor.
|
XPathEvaluator(Configuration config)
Construct an XPathEvaluator with a specified configuration.
|
Modifier and Type | Method and Description |
---|---|
javax.xml.xpath.XPathExpression |
compile(java.lang.String expr)
Compile an XPath 2.0 expression
|
java.lang.String |
evaluate(java.lang.String expr,
org.xml.sax.InputSource inputSource)
Single-shot method to parse and build a source document, and
compile an execute an XPath 2.0 expression, against that document,
returning the result as a string
|
java.lang.Object |
evaluate(java.lang.String expr,
org.xml.sax.InputSource inputSource,
javax.xml.namespace.QName qName)
Single-shot method to parse and build a source document, and
compile an execute an XPath 2.0 expression, against that document
|
java.lang.String |
evaluate(java.lang.String expr,
java.lang.Object node)
Single-shot method to compile an execute an XPath 2.0 expression, returning
the result as a string.
|
java.lang.Object |
evaluate(java.lang.String expr,
java.lang.Object node,
javax.xml.namespace.QName qName)
Single-shot method to compile and execute an XPath 2.0 expression.
|
Configuration |
getConfiguration()
Get the Configuration used by this XPathEvaluator
|
javax.xml.namespace.NamespaceContext |
getNamespaceContext()
Get the namespace context, if one has been set using
setNamespaceContext(javax.xml.namespace.NamespaceContext) |
JAXPXPathStaticContext |
getStaticContext()
Get the current static context.
|
javax.xml.xpath.XPathFunctionResolver |
getXPathFunctionResolver()
Get the resolver for XPath functions
|
javax.xml.xpath.XPathVariableResolver |
getXPathVariableResolver()
Get the resolver for XPath variables
|
void |
importSchema(javax.xml.transform.Source source)
Import a schema.
|
void |
reset() |
void |
setNamespaceContext(javax.xml.namespace.NamespaceContext namespaceContext)
Set the namespace context to be used.
|
void |
setXPathFunctionResolver(javax.xml.xpath.XPathFunctionResolver xPathFunctionResolver)
Set the resolver for XPath functions
|
void |
setXPathVariableResolver(javax.xml.xpath.XPathVariableResolver xPathVariableResolver)
Set the resolver for XPath variables
|
public XPathEvaluator()
public XPathEvaluator(Configuration config)
config
- the configuration to be used. If schema-aware XPath expressions are to be used,
this must be an EnterpriseConfiguration.public Configuration getConfiguration()
public JAXPXPathStaticContext getStaticContext()
public void reset()
reset
in interface javax.xml.xpath.XPath
public void setXPathVariableResolver(javax.xml.xpath.XPathVariableResolver xPathVariableResolver)
setXPathVariableResolver
in interface javax.xml.xpath.XPath
xPathVariableResolver
- a resolver for variablespublic javax.xml.xpath.XPathVariableResolver getXPathVariableResolver()
getXPathVariableResolver
in interface javax.xml.xpath.XPath
public void setXPathFunctionResolver(javax.xml.xpath.XPathFunctionResolver xPathFunctionResolver)
setXPathFunctionResolver
in interface javax.xml.xpath.XPath
xPathFunctionResolver
- a resolver for XPath function callspublic javax.xml.xpath.XPathFunctionResolver getXPathFunctionResolver()
getXPathFunctionResolver
in interface javax.xml.xpath.XPath
public void setNamespaceContext(javax.xml.namespace.NamespaceContext namespaceContext)
setNamespaceContext
in interface javax.xml.xpath.XPath
namespaceContext
- The namespace contextpublic javax.xml.namespace.NamespaceContext getNamespaceContext()
setNamespaceContext(javax.xml.namespace.NamespaceContext)
getNamespaceContext
in interface javax.xml.xpath.XPath
public void importSchema(javax.xml.transform.Source source) throws SchemaException
source
- A Source object identifying the schema document to be loadedSchemaException
- if the schema contained in this document is invalidjava.lang.UnsupportedOperationException
- if the configuration is not schema-awarepublic javax.xml.xpath.XPathExpression compile(java.lang.String expr) throws javax.xml.xpath.XPathExpressionException
compile
in interface javax.xml.xpath.XPath
expr
- the XPath 2.0 expression to be compiled, as a stringjavax.xml.xpath.XPathExpressionException
- if there are any static errors in the expression.
Note that references to undeclared variables are not treated as static errors, because
variables are not pre-declared using this API.public java.lang.Object evaluate(java.lang.String expr, java.lang.Object node, javax.xml.namespace.QName qName) throws javax.xml.xpath.XPathExpressionException
evaluate
in interface javax.xml.xpath.XPath
expr
- The XPath 2.0 expression to be compiled and executednode
- The context node for evaluation of the expression.
This may be a NodeInfo object, representing a node in Saxon's native implementation of the data model, or it may be a node in any supported external object model: DOM, JDOM, DOM4J, or XOM, or any other model for which support has been configured in the Configuration. Note that the supporting libraries for the chosen model must be on the class path.
Contrary to the interface specification, Saxon does not supply an empty document when the value is null. This is because XPath 2.0 allows the context item to be "absent" (null). So Saxon executes the XPath expression with the context item undefined.
qName
- The type of result required. For details, see
XPathExpressionImpl.evaluate(Object, javax.xml.namespace.QName)
XPathExpressionImpl.evaluate(Object, javax.xml.namespace.QName)
javax.xml.xpath.XPathExpressionException
- if any static or dynamic error occurs
in evaluating the expression.public java.lang.String evaluate(java.lang.String expr, java.lang.Object node) throws javax.xml.xpath.XPathExpressionException
evaluate
in interface javax.xml.xpath.XPath
expr
- The XPath 2.0 expression to be compiled and executednode
- The context node for evaluation of the expression
This may be a NodeInfo object, representing a node in Saxon's native implementation of the data model, or it may be a node in any supported external object model: DOM, JDOM, DOM4J, or XOM, or any other model for which support has been configured in the Configuration. Note that the supporting libraries for the chosen model must be on the class path.
Contrary to the interface specification, Saxon does not supply an empty document when the value is null. This is because XPath 2.0 allows the context item to be "absent" (null). So Saxon executes the XPath expression with the context item undefined.
javax.xml.xpath.XPathExpressionException
- if any static or dynamic error occurs
in evaluating the expression.public java.lang.Object evaluate(java.lang.String expr, org.xml.sax.InputSource inputSource, javax.xml.namespace.QName qName) throws javax.xml.xpath.XPathExpressionException
evaluate
in interface javax.xml.xpath.XPath
expr
- The XPath 2.0 expression to be compiled and executedinputSource
- The source document: this will be parsed and built into a tree,
and the XPath expression will be executed with the root node of the tree as the
context node.qName
- The type of result required. For details, see
XPathExpressionImpl.evaluate(Object, javax.xml.namespace.QName)
XPathExpressionImpl.evaluate(Object, javax.xml.namespace.QName)
javax.xml.xpath.XPathExpressionException
- if any static or dynamic error occurs
in evaluating the expression.java.lang.NullPointerException
- if any of the three arguments is nullpublic java.lang.String evaluate(java.lang.String expr, org.xml.sax.InputSource inputSource) throws javax.xml.xpath.XPathExpressionException
evaluate
in interface javax.xml.xpath.XPath
expr
- The XPath 2.0 expression to be compiled and executedinputSource
- The source document: this will be parsed and built into a tree,
and the XPath expression will be executed with the root node of the tree as the
context nodejavax.xml.xpath.XPathExpressionException
- if any static or dynamic error occurs
in evaluating the expression.java.lang.NullPointerException
- if either of the two arguments is nullCopyright (c) 2004-2018 Saxonica Limited. All rights reserved.