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
-
XPathContext(Document, Node, int, int)
- Create a new XPath context.
-
XPathContext(XPathContext)
- Create XPath context based on another context.
-
XPathContext(String)
- Create XPath context from an XML source file.
-
evalBoolean(String)
- Evaluates an XPath expression and converts it to a boolean.
-
evalNodeSet(String)
- Evaluates an XPath expression to return a Node Set.
-
evalNumber(String)
- Evaluates an XPath expression and converts it to a number.
-
evalString(String)
- Evaluates an XPath expression and converts it to a String.
-
getDocument()
- Get the Document of the XPath context.
-
getNode()
- Get the current node of the XPath context.
-
getPosition()
- Get the current position of the XPath context.
-
getSize()
- Get the current size of the XPath context.
-
getVariable(String)
- Get the value of a variable in the XPath context.
-
pop()
- Restore the context node, position, and size from the stack
-
push(Node, int, int)
- Push context node, position, and size into the stack
and set a new current node, position and size.
-
setDocument(Document)
- Set the Document.
-
setNode(Node)
- Set the current node of the XPath context.
-
setPosition(int)
- Set the current position of the XPath context.
-
setSize(int)
- Set the current size of the XPath context.
-
setVariable(String, Object)
- Set the value of a variable in the XPath context.
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
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.
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.
evalBoolean
public boolean evalBoolean(String path) throws Exception
- Evaluates an XPath expression and converts it to a boolean.
evalNodeSet
public org.w3c.dom.NodeList evalNodeSet(String path) throws Exception
- Evaluates an XPath expression to return a Node Set.
evalNumber
public double evalNumber(String path) throws Exception
- Evaluates an XPath expression and converts it to a number.
evalString
public java.lang.String evalString(String path) throws Exception
- Evaluates an XPath expression and converts it to a String.
getDocument
public org.w3c.dom.Document getDocument()
- Get the Document of the XPath context.
getNode
public org.w3c.dom.Node getNode()
- Get the current node of the XPath context.
getPosition
public int getPosition()
- Get the current position of the XPath context.
getSize
public int getSize()
- Get the current size of the XPath context.
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.
pop
public void pop() throws Exception
- Restore the context node, position, and size from the stack
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.
setDocument
public void setDocument(Document d)
- Set the Document.
setNode
public void setNode(Node n)
- Set the current node of the XPath context.
setPosition
public void setPosition(int j)
- Set the current position of the XPath context.
setSize
public void setSize(int j)
- Set the current size of the XPath context.
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.