Class XPathEvaluator

  • Direct Known Subclasses:

    public class XPathEvaluator
    extends java.lang.Object
    This class provides a native Saxon API for free-standing evaluation of XPath expressions. This is the primitive XPath interface used internally within Saxon.

    The preferred API for user applications calling XPath is the s9api XPathCompiler interface.

    • Constructor Detail

      • XPathEvaluator

        public XPathEvaluator​(Configuration config)
        Construct an XPathEvaluator with a specified configuration.
        config - the configuration to be used. If the XPathEvaluator is to be used to run schema-aware XPath expressions this must be an instance of EnterpriseConfiguration
    • Method Detail

      • getConfiguration

        public Configuration getConfiguration()
        Get the Configuration in use.
        the Saxon configuration
      • setStaticContext

        public void setStaticContext​(XPathStaticContext context)
        Set the static context for compiling XPath expressions. This provides more detailed 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.
        context - the XPath static context

        Setting a new static context clears any variables and namespaces that have previously been declared.

      • getStaticContext

        public XPathStaticContext getStaticContext()
        Get the current static context. This will always return a value; if no static context has been supplied by the user, the system will have created its own. A system-created static context will always be an instance of IndependentContext
        the static context object
      • createExpression

        public XPathExpression createExpression​(java.lang.String expression)
                                         throws XPathException
        Prepare (compile) an XPath expression for subsequent evaluation.
        expression - The XPath expression to be compiled, supplied as a string.
        an XPathExpression object representing the prepared expression
        XPathException - if the syntax of the expression is wrong, or if it references namespaces, variables, or functions that have not been declared.
      • postProcess

        protected Expression postProcess​(Expression exp,
                                         ExpressionVisitor visitor,
                                         ContextItemStaticInfo cit)
                                  throws XPathException
        Customize the expression post-optimization. This method does nothing, but can be overridden in a subclass
        exp - the expression after optimization
        visitor - an expression visitor that includes static context information
        cit - information about the context item type
      • createPattern

        public XPathExpression createPattern​(java.lang.String pattern)
                                      throws XPathException
        Prepare (compile) an XSLT pattern for subsequent evaluation. The result is an XPathExpression object representing a (pseudo-) expression that when evaluated returns a boolean result: true if the context node matches the pattern, false if it does not.
        pattern - the XSLT pattern to be compiled, supplied as a string
        an XPathExpression object representing the pattern, wrapped as an expression
        XPathException - if the syntax of the expression is wrong, or if it references namespaces, variables, or functions that have not been declared.