public class XPathSelector extends java.lang.Object implements java.lang.Iterable<XdmItem>
Modifier | Constructor and Description |
---|---|
protected |
XPathSelector(XPathExpression exp,
java.util.Map<StructuredQName,XPathVariable> declaredVariables) |
Modifier and Type | Method and Description |
---|---|
boolean |
effectiveBooleanValue()
Evaluate the XPath expression, returning the effective boolean value of the result.
|
XdmValue |
evaluate()
Evaluate the expression, returning the result as an
XdmValue (that is,
a sequence of nodes and/or atomic values). |
XdmItem |
evaluateSingle()
Evaluate the XPath expression, returning the result as an
XdmItem (that is,
a single node or atomic value). |
XdmItem |
getContextItem()
Get the context item used for evaluating the XPath expression.
|
XPathDynamicContext |
getUnderlyingXPathContext()
Get the underlying dynamic context object.
|
javax.xml.transform.URIResolver |
getURIResolver()
Get the URI resolver.
|
java.util.Iterator<XdmItem> |
iterator()
Evaluate the expression, returning the result as an
Iterator (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 |
setURIResolver(javax.xml.transform.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 variable
|
protected XPathSelector(XPathExpression exp, java.util.Map<StructuredQName,XPathVariable> declaredVariables)
public void setContextItem(XdmItem item) throws SaxonApiException
DocumentBuilder.build(javax.xml.transform.Source)
method.item
- The context item for evaluating the expression. Must not be null.SaxonApiException
- if an error occurs, for example because the type
of item supplied does not match the required item typepublic XdmItem getContextItem()
public void setVariable(QName name, XdmValue value) throws SaxonApiException
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.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 declaredpublic void setURIResolver(javax.xml.transform.URIResolver resolver)
resolver
- An object that implements the URIResolver interface, or null.public javax.xml.transform.URIResolver getURIResolver()
public XdmValue evaluate() throws SaxonApiException
XdmValue
(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 the evaluateSingle
method, which
does guarantee that an XdmItem
(or null) will be returned.
XdmValue
representing the results of the expression.SaxonApiException
- if a dynamic error occurs during the expression evaluation.public XdmItem evaluateSingle() throws SaxonApiException
XdmItem
(that is,
a single node or atomic value).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.SaxonApiException
- if a dynamic error occurs during the expression evaluation.public java.util.Iterator<XdmItem> iterator() throws SaxonApiUncheckedException
Iterator
(that is,
an iterator over a sequence of nodes and/or atomic values).
Because an XPathSelector
is an Iterable
, 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); }
iterator
in interface java.lang.Iterable<XdmItem>
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.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 the hasNext()
method of the returned iterator.public boolean effectiveBooleanValue() throws SaxonApiException
boolean
representing the effective boolean value of the result of evaluating
the expression, as defined by the rules for the fn:boolean() function.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)public XPathDynamicContext getUnderlyingXPathContext()
Copyright (c) 2004-2018 Saxonica Limited. All rights reserved.