Class XPathExpression


  • public class XPathExpression
    extends java.lang.Object
    This class is a representation of an XPath Expression for use with the XPathEvaluator class. It is modelled on the XPath API defined in JAXP 1.3, but is cut down to remove any dependencies on JAXP 1.3, making it suitable for use on vanilla JDK 1.4 installations.
    Author:
    Michael H. Kay
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected XPathExpression​(XPathEvaluator evaluator, Expression exp)
      The constructor is protected, to ensure that instances can only be created using the createExpression() method of XPathEvaluator
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      XPathContext createDynamicContext​(Item contextItem)
      Create a dynamic context suitable for evaluating this expression
      java.util.List evaluate​(javax.xml.transform.Source source)
      Execute a prepared XPath expression, returning the results as a List.
      java.lang.Object evaluateSingle​(javax.xml.transform.Source source)
      Execute a prepared XPath expression, returning the first item in the result.
      Expression getInternalExpression()
      Low-level method to get the internal Saxon expression object.
      SequenceIterator rawIterator​(javax.xml.transform.Source source)
      Get a raw iterator over the results of the expression.
      protected void setStackFrameMap​(SlotManager map)
      Define the number of slots needed for local variables within the expression
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • XPathExpression

        protected XPathExpression​(XPathEvaluator evaluator,
                                  Expression exp)
        The constructor is protected, to ensure that instances can only be created using the createExpression() method of XPathEvaluator
    • Method Detail

      • setStackFrameMap

        protected void setStackFrameMap​(SlotManager map)
        Define the number of slots needed for local variables within the expression
      • createDynamicContext

        public XPathContext createDynamicContext​(Item contextItem)
        Create a dynamic context suitable for evaluating this expression
        Parameters:
        contextItem - the initial context item
        Returns:
        an XPathContext object representing a suitable dynamic context. This will be initialized with a stack frame suitable for holding the variables used by the expression.
      • evaluate

        public java.util.List evaluate​(javax.xml.transform.Source source)
                                throws XPathException
        Execute a prepared XPath expression, returning the results as a List.
        Parameters:
        source - the document or other node against which the XPath expression will be evaluated. This may be a Saxon NodeInfo object, representing a node in an existing tree, or it may be any kind of JAXP Source object such as a StreamSource SAXSource or DOMSource.
        Returns:
        The results of the expression, as a List. The List represents the sequence of items returned by the expression. Each item in the list will either be an instance of net.sf.saxon.om.NodeInfo, representing a node, or a Java object representing an atomic value.
        Throws:
        XPathException
      • evaluateSingle

        public java.lang.Object evaluateSingle​(javax.xml.transform.Source source)
                                        throws XPathException
        Execute a prepared XPath expression, returning the first item in the result. This is useful where it is known that the expression will only return a singleton value (for example, a single node, or a boolean).
        Parameters:
        source - the document or other node against which the XPath expression will be evaluated. This may be a Saxon NodeInfo object, representing a node in an existing tree, or it may be any kind of JAXP Source object such as a StreamSource SAXSource or DOMSource.
        Returns:
        The first item in the sequence returned by the expression. If the expression returns an empty sequence, this method returns null. Otherwise, it returns the first item in the result sequence, represented as a Java object using the same mapping as for the evaluate() method
        Throws:
        XPathException
      • rawIterator

        public SequenceIterator rawIterator​(javax.xml.transform.Source source)
                                     throws XPathException
        Get a raw iterator over the results of the expression. This returns results without any conversion of the returned items to "native" Java classes. This method is intended for use by applications that need to process the results of the expression using internal Saxon interfaces.
        Parameters:
        source - the document or other node against which the XPath expression will be evaluated. This may be a Saxon NodeInfo object, representing a node in an existing tree, or it may be any kind of JAXP Source object such as a StreamSource SAXSource or DOMSource.
        Throws:
        XPathException
      • getInternalExpression

        public Expression getInternalExpression()
        Low-level method to get the internal Saxon expression object. This exposes a wide range of internal methods that may be needed by specialized applications, and allows greater control over the dynamic context for evaluating the expression.
        Returns:
        the underlying Saxon expression object.