net.sf.saxon.s9api
Class XPathCompiler
java.lang.Object
net.sf.saxon.s9api.XPathCompiler
public class XPathCompiler
extends java.lang.Object
An XPathCompiler object allows XPath queries to be compiled. The compiler holds information that
represents the static context for an XPath expression.
To construct an XPathCompiler, use the factory method
Processor.newXPathCompiler()
.
An XPathCompiler may be used repeatedly to compile multiple
queries. Any changes made to the XPathCompiler (that is, to the
static context) do not affect queries that have already been compiled.
An XPathCompiler may be used concurrently in multiple threads, but
it should not then be modified once initialized.
Changes to an XPathCompiler are cumulative. There is no simple way to reset
the XPathCompiler to its initial state; instead, simply create a new
XPathCompiler.
XPathExecutable | compile(String source) - Compile an XPath expression, supplied as a character string.
|
void | declareNamespace(String prefix, String uri) - Declare a namespace binding as part of the static context for XPath expressions compiled using this
XPathCompiler
|
void | declareVariable(QName qname) - Declare a variable as part of the static context for XPath expressions compiled using this
XPathCompiler.
|
void | declareVariable(QName qname, ItemType itemType, OccurrenceIndicator occurrences) - Declare a variable as part of the static context for XPath expressions compiled using this
XPathCompiler.
|
URI | getBaseURI() - Get the static base URI for XPath expressions compiled using this XPathCompiler.
|
boolean | isBackwardsCompatible() - Ask whether XPath 1.0 backwards compatibility mode is in force.
|
void | setBackwardsCompatible(boolean option) - Set whether XPath 1.0 backwards compatibility mode is to be used.
|
void | setBaseURI(URI uri) - Set the static base URI for XPath expressions compiled using this XPathCompiler.
|
XPathCompiler
protected XPathCompiler(Configuration config)
Protected constructor
config
- the Saxon configuration
compile
public XPathExecutable compile(String source)
throws SaxonApiException
Compile an XPath expression, supplied as a character string.
source
- A string containing the source text of the XPath expression
- An XPathExecutable which represents the compiled xpath expression object.
The XPathExecutable may be run as many times as required, in the same or a different thread.
The XPathExecutable is not affected by any changes made to the XPathCompiler once it has been compiled.
declareNamespace
public void declareNamespace(String prefix,
String uri)
Declare a namespace binding as part of the static context for XPath expressions compiled using this
XPathCompiler
prefix
- The namespace prefix. If the value is a zero-length string, this method sets the default
namespace for elements and types.uri
- The namespace URI. It is possible to specify a zero-length string to "undeclare" a namespace;
in this case the prefix will not be available for use, except in the case where the prefix
is also a zero length string, in which case the absence of a prefix implies that the name
is in no namespace.
declareVariable
public void declareVariable(QName qname)
Declare a variable as part of the static context for XPath expressions compiled using this
XPathCompiler. It is an error for the XPath expression to refer to a variable unless it has been
declared. This method declares the existence of the variable, but it does not
bind any value to the variable; that is done later, when the XPath expression is evaluated.
The variable is allowed to have any type (that is, the required type is item()*
).
qname
- The name of the variable, expressions as a QName
declareVariable
public void declareVariable(QName qname,
ItemType itemType,
OccurrenceIndicator occurrences)
throws SaxonApiException
Declare a variable as part of the static context for XPath expressions compiled using this
XPathCompiler. It is an error for the XPath expression to refer to a variable unless it has been
declared. This method declares the existence of the variable, and defines the required type
of the variable, but it does not bind any value to the variable; that is done later,
when the XPath expression is evaluated.
qname
- The name of the variable, expressed as a QNameitemType
- The required item type of the value of the variableoccurrences
- The allowed number of items in the sequence forming the value of the variable
SaxonApiException
- if the requiredType is syntactically invalid or if it refers to namespace
prefixes or schema components that are not present in the static context
getBaseURI
public URI getBaseURI()
Get the static base URI for XPath expressions compiled using this XPathCompiler. The base URI
is part of the static context, and is used to resolve any relative URIs appearing within an XPath
expression, for example a relative URI passed as an argument to the doc() function. If no
static base URI has been explicitly set, this method returns null.
- the base URI from the static context
isBackwardsCompatible
public boolean isBackwardsCompatible()
Ask whether XPath 1.0 backwards compatibility mode is in force.
- true if XPath 1.0 backwards compatibility is enabled, false if it is disabled.
setBackwardsCompatible
public void setBackwardsCompatible(boolean option)
Set whether XPath 1.0 backwards compatibility mode is to be used. In backwards compatibility
mode, more implicit type conversions are allowed in XPath expressions, for example it
is possible to compare a number with a string. The default is false (backwards compatibility
mode is off).
option
- true if XPath 1.0 backwards compatibility is to be enabled, false if it is to
be disabled.
setBaseURI
public void setBaseURI(URI uri)
Set the static base URI for XPath expressions compiled using this XPathCompiler. The base URI
is part of the static context, and is used to resolve any relative URIs appearing within an XPath
expression, for example a relative URI passed as an argument to the doc() function. If no
static base URI is supplied, then the current working directory is used.
uri
- the base URI to be set in the static context. This must be an absolute URI.