## net.sf.saxon.xpath
Class XPathEvaluator

    java.lang.Object
      |
      +--net.sf.saxon.xpath.XPathEvaluator

public class XPathEvaluator
extends java.lang.Object

XPathEvaluator provides a simple API for standalone XPath processing (that is, executing XPath expressions in the absence of an XSLT stylesheet). It is loosely modelled on the proposed org.w3c.dom.xpath.XPathEvaluator interface, though it does not actually implement this interface at present.

Constructor Summary
`XPathEvaluator()` Default constructor.
`XPathEvaluator(javax.xml.transform.Source source)` Construct an XPathEvaluator to process a particular source document.

Method Summary
`static java.lang.Object` `convert(Item item)` Internal method to convert an XPath value to a Java object.
`XPathExpression` `createExpression(java.lang.String expression)` Prepare an XPath expression for subsequent evaluation.
`java.util.List` `evaluate(java.lang.String expression)` Prepare and execute an XPath expression, supplied as a string, and returning the results as a List.
`java.lang.Object` `evaluateSingle(java.lang.String expression)` Prepare and execute an XPath expression, supplied as a string, and returning the first item in the result.
`StaticContext` `getStaticContext()` Get the current static context
`static void` `main(java.lang.String[] args)` A simple command-line interface for the XPathEvaluator (not documented).
`void` `setContextNode(NodeInfo node)` Set the context node.
`NodeInfo` `setSource(javax.xml.transform.Source source)` Supply the document against which XPath expressions are to be executed.
`void` `setStaticContext(StaticContext 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.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### XPathEvaluator

    public XPathEvaluator()

  Default constructor. If this constructor is used, a source document must be subsequently supplied using the setSource() method.

### XPathEvaluator

    public XPathEvaluator(javax.xml.transform.Source source)
                   throws XPathException

  Construct an XPathEvaluator to process a particular source document. This is equivalent to using the default constructor and immediately calling setSource().

Parameters:
  `source` - The source document (or a specific node within it).

Method Detail

### setStripSpace

    public void setStripSpace(boolean strip)

  Indicate whether all whitespace text nodes in the source document are to be removed. This option has no effect unless it is called before the call on setSource(), and unless the Source supplied to setSource() is a SAXSource or StreamSource.

  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.

### setSource

    public NodeInfo setSource(javax.xml.transform.Source source)
                       throws XPathException

  Supply the document against which XPath expressions are to be executed. This method must be called before preparing or executing an XPath expression. Setting a new source document clears all the namespaces that have been declared.

  Parameters:
    `source` - Any javax.xml.transform.Source object representing the document against which XPath expressions will be executed. Note that a Saxon `DocumentInfo` (indeed any `NodeInfo`) can be used as a Source. To use a third-party DOM Document as a source, create an instance of `DOMSource` to wrap it.

    The Source object supplied also determines the initial setting of the context item. In most cases the context node will be the root of the supplied document; however, if a NodeInfo or DOMSource is supplied it can be any node in the document.

  Returns:
    the NodeInfo of the start node in the resulting document object.
    `XPathException`

### setStaticContext

    public void setStaticContext(StaticContext context)

  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 StandaloneContext 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

    public StaticContext getStaticContext()

  Get the current static context

### createExpression

    public XPathExpression createExpression(java.lang.String expression)
                                     throws XPathException

  Prepare an XPath expression for subsequent evaluation. The prepared expression can only be used with the document that has been established using setSource() at the time this method is called.

  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.

### setContextNode

    public void setContextNode(NodeInfo node)

  Set the context node. This provides the context node for any expressions executed after this method is called, including expressions that were prepared before it was called.

  Parameters:
    `node` - The node to be used as the context node. This must be a node within the context document (the document supplied using the setSource() method).
  Throws:
    `java.lang.NullPointerException` - if the argument is null
    `java.lang.IllegalArgumentException` - if the supplied node is not a node in the context document

### evaluate

    public java.util.List evaluate(java.lang.String expression)
                            throws XPathException

  Prepare and execute an XPath expression, supplied as a string, and returning the results as a List.

  Parameters:
    `expression` - The XPath expression to be evaluated, supplied as a string.
  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 object representing a node, or a Java object representing an atomic value. The types of Java object that may be included in the list, and the XML Schema data types that they correspond to, are as follows:

    - Boolean (xs:boolean)
    - String (xs:string)
    - BigDecimal (xs:decimal)
    - Long (xs:integer and its derived types)
    - Double (xs:double)
    - Float (xs:float)
    - Date (xs:date, xs:dateTime)
    `XPathException`

### convert

    public static java.lang.Object convert(Item item)
                                    throws XPathException

  Internal method to convert an XPath value to a Java object. An atomic value is returned as an instance of the best available Java class. If the item is a node, the node is "unwrapped", to return the underlying node in the original model (which might be, for example, a DOM or JDOM node).

    `XPathException`

### evaluateSingle

    public java.lang.Object evaluateSingle(java.lang.String expression)
                                    throws XPathException

  Prepare and execute an XPath expression, supplied as a string, and 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:
    `expression` - The XPath expression to be evaluated, supplied as a string.
  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
    `XPathException`

### main

    public static void main(java.lang.String[] args)
                     throws java.lang.Exception

  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.

    `java.lang.Exception`