Class XPathSelector
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
XPathSelector
(XPathExpression exp, Map<StructuredQName, XPathVariable> declaredVariables) -
Method Summary
Modifier and TypeMethodDescriptionboolean
Evaluate the XPath expression, returning the effective boolean value of the result.evaluate()
Evaluate the expression, returning the result as anXdmValue
(that is, a sequence of nodes and/or atomic values).Evaluate the XPath expression, returning the result as anXdmItem
(that is, a single node or atomic value).Get the context item used for evaluating the XPath expression.Get the resource resolver.Get the underlying dynamic context object.Get the URI resolver used forfn:unparsed-text()
and related functions.Get the URI resolver.iterator()
Evaluate the expression, returning the result as anIterator
(that is, an iterator over a sequence of nodes and/or atomic values).void
setContextItem
(XdmItem item) Set the context item for evaluating the XPath expression.void
setErrorReporter
(ErrorReporter reporter) Set a callback to be used for reporting of run-time conditions.void
setResourceResolver
(ResourceResolver resolver) Set an object that will be used to resolve URIs used in fn:doc() and related functions.void
Set an object that will be used to resolve URIs used infn:unparsed-text()
and related functions.void
setURIResolver
(URIResolver resolver) Set an object that will be used to resolve URIs used in fn:doc() and related functions.void
setVariable
(QName name, XdmValue value) Set the value of a variablestream()
Evaluate the expression, returning the result as anStream
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
XPathSelector
-
-
Method Details
-
setContextItem
Set the context item for evaluating the XPath expression. This may be either a node or an atomic value. Most commonly it will be a document node, which might be constructed using theDocumentBuilder.build(javax.xml.transform.Source)
method.- Parameters:
item
- The context item for evaluating the expression. Must not be null.- Throws:
SaxonApiException
- if an error occurs, for example because the type of item supplied does not match the required item type
-
getContextItem
Get the context item used for evaluating the XPath expression. This may be either a node or an atomic value. Most commonly it will be a document node, which might be constructed using the Build method of the DocumentBuilder object.- Returns:
- The context item for evaluating the expression, or null if no context item has been set.
-
setVariable
Set the value of a variable- Parameters:
name
- The name of the variable. This must match the name of a variable that was declared to the XPathCompiler. No error occurs if the expression does not actually reference a variable with this name.value
- The value to be given to the variable.- Throws:
SaxonApiException
- if the variable has not been declared or if the type of the value supplied does not conform to the required type that was specified when the variable was declared
-
setResourceResolver
Set an object that will be used to resolve URIs used in fn:doc() and related functions.- Parameters:
resolver
- An object that implements the ResourceResolver interface, or null.- Since:
- 9.4
-
getResourceResolver
Get the resource resolver.- Returns:
- the user-supplied resource resolver if there is one, or the system-defined one otherwise
- Since:
- 9.4
-
setURIResolver
Set an object that will be used to resolve URIs used in fn:doc() and related functions.- Parameters:
resolver
- An object that implements the URIResolver interface, or null.- Since:
- 9.4
-
getURIResolver
Get the URI resolver.- Returns:
- the user-supplied URI resolver if there is one, or the system-defined one otherwise
- Since:
- 9.4
-
setUnparsedTextResolver
Set an object that will be used to resolve URIs used infn:unparsed-text()
and related functions.- Parameters:
resolver
- An object that implements the UnparsedTextURIResolver interface, or null.- Since:
- 11
-
getUnparsedTextURIResolver
Get the URI resolver used forfn:unparsed-text()
and related functions.- Returns:
- the user-supplied URI resolver if there is one, or the system-defined one otherwise
- Since:
- 11
-
setErrorReporter
Set a callback to be used for reporting of run-time conditions. Note that fatal run-time errors are always reported by throwing an exception, and are not notified to theErrorReporter
.This method is therefore not especially useful; its only real effect is to control the way that warnings are reported, and there are not many conditions in pure XPath processing that result in warnings being generated dynamically.
By default, warnings are reported to a default error reporter which writes to the logging destination associated with the Saxon
Configuration
, which in turn defaults to the system error stream.- Parameters:
reporter
- the user-supplied error reporter to be called when run-time warnings arise- Since:
- 10.0
-
evaluate
Evaluate the expression, returning the result as anXdmValue
(that is, a sequence of nodes and/or atomic values).Note: Although a singleton result may be represented as an
XdmItem
, there is no guarantee that this will always be the case. If you know that the expression will return at most one node or atomic value, it is best to use theevaluateSingle
method, which does guarantee that anXdmItem
(or null) will be returned.- Returns:
- An
XdmValue
representing the results of the expression. - Throws:
SaxonApiException
- if a dynamic error occurs during the expression evaluation.
-
evaluateSingle
Evaluate the XPath expression, returning the result as anXdmItem
(that is, a single node or atomic value).- Returns:
- an
XdmItem
representing the result of the expression, or null if the expression returns an empty sequence. If the expression returns a sequence of more than one item, any items after the first are ignored. - Throws:
SaxonApiException
- if a dynamic error occurs during the expression evaluation.
-
iterator
Evaluate the expression, returning the result as anIterator
(that is, an iterator over a sequence of nodes and/or atomic values).Because an
XPathSelector
is anIterable
, it is possible to iterate over the result using a Java 5 "for each" expression, for example:XPathCompiler compiler = processor.newXPathCompiler(); XPathSelector seq = compiler.compile("1 to 20").load(); for (XdmItem item : seq) { System.err.println(item); }
- Specified by:
iterator
in interfaceIterable<XdmItem>
- Returns:
- An iterator over the sequence that represents the results of the expression.
Each object in this sequence will be an instance of
XdmItem
. Note that the expression may be evaluated lazily, which means that a successful response from this method does not imply that the expression has executed successfully: failures may be reported later while retrieving items from the iterator. - Throws:
SaxonApiUncheckedException
- if a dynamic error occurs during XPath evaluation that can be detected at this point. It is also possible that an SaxonApiUncheckedException will be thrown by thehasNext()
method of the returned iterator.
-
stream
Evaluate the expression, returning the result as anStream
.- Returns:
- A stream delivering the results of the expression.
Each object in this stream will be an instance of
XdmItem
. Note that the expression may be evaluated lazily, which means that a successful response from this method does not imply that the expression has executed successfully: failures may be reported later while retrieving items from the iterator. - Throws:
SaxonApiUncheckedException
- if a dynamic error occurs during XPath evaluation that can be detected at this point.
-
effectiveBooleanValue
Evaluate the XPath expression, returning the effective boolean value of the result.- Returns:
- a
boolean
representing the effective boolean value of the result of evaluating the expression, as defined by the rules for the fn:boolean() function. - Throws:
SaxonApiException
- if a dynamic error occurs during the expression evaluation, or if the result of the expression is a value whose effective boolean value is not defined (for example, a date or a sequence of three integers)- Since:
- 9.1
-
getUnderlyingXPathContext
Get the underlying dynamic context object. This provides an escape hatch to the underlying implementation classes, which contain methods that may change from one release to another.- Returns:
- the underlying object representing the dynamic context for query execution
-