Class XPathContext

Class XPathContext

Object
   |
   +----XPathContext

public class XPathContext
extends Object
This class provides a standard interface to XPath. It is currently implemented using James Clark's xt and Takuki Kamiya's omquery. An XPathContext is an object representing the information that must be provided for evaluating XPath expressions. An XPath context includes: current node (sometimes called the context node), two integers (position and size), a set of variables and their values. It should also include a function library and namesspaces, but these are not provided in this implementation. To facilitate ease of use, XPathContext includes an easy way of saving and restoring the context by using a simple stack. At this time, only the current node, position and size are saved on the stack.

Version:
1.0
Author:
Craig Cleaveland

Constructor Index

 o XPathContext(Document, Node, int, int)
Create a new XPath context.
 o XPathContext(XPathContext)
Create XPath context based on another context.
 o XPathContext(String)
Create XPath context from an XML source file.

Method Index

 o evalBoolean(String)
Evaluates an XPath expression and converts it to a boolean.
 o evalNodeSet(String)
Evaluates an XPath expression to return a Node Set.
 o evalNumber(String)
Evaluates an XPath expression and converts it to a number.
 o evalString(String)
Evaluates an XPath expression and converts it to a String.
 o getDocument()
Get the Document of the XPath context.
 o getNode()
Get the current node of the XPath context.
 o getPosition()
Get the current position of the XPath context.
 o getSize()
Get the current size of the XPath context.
 o getVariable(String)
Get the value of a variable in the XPath context.
 o pop()
Restore the context node, position, and size from the stack
 o push(Node, int, int)
Push context node, position, and size into the stack and set a new current node, position and size.
 o setDocument(Document)
Set the Document.
 o setNode(Node)
Set the current node of the XPath context.
 o setPosition(int)
Set the current position of the XPath context.
 o setSize(int)
Set the current size of the XPath context.
 o setVariable(String, Object)
Set the value of a variable in the XPath context.

Constructors

 o XPathContext
public XPathContext(Document d,
                    Node n,
                    int p,
                    int s)
Create a new XPath context.

Parameters:
d - The XML document
n - The current node
p - The position
s - The size
 o XPathContext
public XPathContext(XPathContext x)
Create XPath context based on another context. Clones a copy of the XPath context. At this time, only the current node, position and size are copied.

 o XPathContext
public XPathContext(String xmlSource) throws Exception
Create XPath context from an XML source file. The parameters specifies the XML source as a URL. An XML Document will be constructed from the XML file. The current node will be set to the document element and the position and size are set to 1.

Methods

 o evalBoolean
public boolean evalBoolean(String path) throws Exception
Evaluates an XPath expression and converts it to a boolean.

 o evalNodeSet
public org.w3c.dom.NodeList evalNodeSet(String path) throws Exception
Evaluates an XPath expression to return a Node Set.

 o evalNumber
public double evalNumber(String path) throws Exception
Evaluates an XPath expression and converts it to a number.

 o evalString
public java.lang.String evalString(String path) throws Exception
Evaluates an XPath expression and converts it to a String.

 o getDocument
public org.w3c.dom.Document getDocument()
Get the Document of the XPath context.

 o getNode
public org.w3c.dom.Node getNode()
Get the current node of the XPath context.

 o getPosition
public int getPosition()
Get the current position of the XPath context.

 o getSize
public int getSize()
Get the current size of the XPath context.

 o getVariable
public java.lang.Object getVariable(String var)
Get the value of a variable in the XPath context. The type of the value will be one of the following: Double, Boolean, String, Node, or NodeList.

 o pop
public void pop() throws Exception
Restore the context node, position, and size from the stack

 o push
public void push(Node n,
                 int p,
                 int s)
Push context node, position, and size into the stack and set a new current node, position and size.

 o setDocument
public void setDocument(Document d)
Set the Document.

 o setNode
public void setNode(Node n)
Set the current node of the XPath context.

 o setPosition
public void setPosition(int j)
Set the current position of the XPath context.

 o setSize
public void setSize(int j)
Set the current size of the XPath context.

 o setVariable
public void setVariable(String var,
                        Object value) throws Exception
Set the value of a variable in the XPath context. The value of the variable must be an XPath type which may be any of the following: Double, Node, String, Boolean, or NodeList.