Package net.sf.saxon.sxpath
Class XPathEvaluator
java.lang.Object
net.sf.saxon.sxpath.XPathEvaluator
This is a cut-down version of the XPathEvaluator in the net.sf.saxon.xpath package. It provides
much of the same functionality, but without any dependencies on the JAXP 1.3 interfaces, which
are not available in JDK 1.4. The main restrictions are that it does not support mechanisms for
defining variables or functions.
- Author:
- Michael H. Kay
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.XPathEvaluator
(Configuration config) Construct an XPathEvaluator with a specified configuration. -
Method Summary
Modifier and TypeMethodDescriptionBuild a source document.createExpression
(String expression) Prepare an XPath expression for subsequent evaluation.Get the Configuration in useGet the external namespace resolver, if one has been set usingsetNamespaceResolver(net.sf.saxon.om.NamespaceResolver)
Get the current static context.static void
A simple command-line interface for the XPathEvaluator (not documented).void
Set the default namespace for elements and typesvoid
setNamespaceResolver
(NamespaceResolver namespaceContext) Set the external namespace resolver to be used.void
setStaticContext
(IndependentContext context) Set the static context for compiling XPath expressions.void
setStripSpace
(boolean strip) Indicate whether all whitespace text nodes in the source document are to be removed.
-
Constructor Details
-
XPathEvaluator
public XPathEvaluator()Default constructor. Creates an XPathEvaluator with a default configuration and name pool. -
XPathEvaluator
Construct an XPathEvaluator with a specified configuration.- Parameters:
config
- the configuration to be used
-
-
Method Details
-
getConfiguration
Get the Configuration in use -
setStripSpace
public void setStripSpace(boolean strip) Indicate whether all whitespace text nodes in the source document are to be removed.- Parameters:
strip
- True if all whitespace text nodes are to be stripped from the source document, false otherwise. The default if the method is not called is false.
-
build
Build a source document.- Parameters:
source
- a JAXP Source object. This may be any implementation of Source that Saxon recognizes: not only the standard kinds of source such as StreamSource, SAXSource, and DOMSource, but also for example a JDOM or XOM DocumentWrapper.- Returns:
- the NodeInfo representing the root of the constructed tree.
- Throws:
XPathException
- if, for example, XML parsing fails.
-
setStaticContext
Set the static context for compiling XPath expressions. This provides control over the environment in which the expression is compiled, for example it allows namespace prefixes to be declared, variables to be bound and functions to be defined. For most purposes, the static context can be defined by providing and tailoring an instance of the IndependentContext class. Until this method is called, a default static context is used, in which no namespaces are defined other than the standard ones (xml, xslt, and saxon), and no variables or functions (other than the core XPath functions) are available. -
getStaticContext
Get the current static context. This will always return a value; if no static context has been supplied by the user, the system creates its own. -
createExpression
Prepare an XPath expression for subsequent evaluation.- Parameters:
expression
- The XPath expression to be evaluated, supplied as a string.- Returns:
- an XPathExpression object representing the prepared expression
- Throws:
XPathException
- if the syntax of the expression is wrong, or if it references namespaces, variables, or functions that have not been declared.
-
setNamespaceResolver
Set the external namespace resolver to be used. This overrides any namespaces declared directly using declareNamespace on the staticContext object- Parameters:
namespaceContext
- The namespace context
-
getNamespaceResolver
Get the external namespace resolver, if one has been set usingsetNamespaceResolver(net.sf.saxon.om.NamespaceResolver)
- Returns:
- the namespace context if set, or null otherwise
-
setDefaultElementNamespace
Set the default namespace for elements and types- Parameters:
uri
- The namespace to be used to qualify unprefixed element names and type names appearing in the XPath expression.
-
main
A simple command-line interface for the XPathEvaluator (not documented). First parameter is the filename containing the source document, second parameter is the XPath expression.- Throws:
Exception
-