|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.caucho.xpath.XPath
Public facade for selecting nodes and creating match patterns.
Applications can select nodes directly from the XPath facade.
For example,
Node verse = XPath.find("chapter/verse", node);
For greater efficiency, applications can also precompile the
match patterns.
Pattern pattern = XPath.parseSelect("chapter/verse");
Node verse = pattern.find(node);
XPath can also return values based on XPath expressions, following
the XPath expression syntax. Applications can use the expressions for
the equivalent of xsl:value-of
Expr expr = XPath.parseExpr("chapter/verse/@id + 1");
double value = expr.evalNumber(node);
To support the XPath pattern variables, XPath uses an environment object. Most applications will not need to use it.
Method Summary | |
static Env |
createEnv()
Creates a new variable environment. |
static Env |
createEnv(Env global)
Creates a new variable environment based on an old environment. |
static double |
evalNumber(java.lang.String query,
Node node)
Evaluates an XPath expression, returning a double. |
static java.lang.Object |
evalObject(java.lang.String query,
Node node)
Evaluates an XPath expression, returning an object |
static java.lang.String |
evalString(java.lang.String query,
Node node)
Evaluates an XPath expression, returning a string. |
static Node |
find(java.lang.String query,
Node node)
Finds a node based on an XPath pattern. |
static void |
freeEnv(Env env)
Free an environment. |
static Expr |
parseExpr(java.lang.String query)
Parses an XPath expression for later evaluation. |
static Expr |
parseExpr(java.lang.String query,
NamespaceContext namespace)
Parses an XPath expression for later evaluation. |
static Expr |
parseExpr(java.lang.String query,
NamespaceContext namespace,
Pattern nodeList)
Parses an XPath expression for later evaluation. |
static Pattern |
parseMatch(java.lang.String query)
Create a node match pattern. |
static Pattern |
parseMatch(java.lang.String query,
NamespaceContext namespace)
Create a node match pattern. |
static Pattern |
parseSelect(java.lang.String query)
Create a node selection pattern. |
static Pattern |
parseSelect(java.lang.String query,
NamespaceContext namespace)
Create a node selection pattern. |
static java.util.Iterator |
select(java.lang.String query,
Node node)
Selects all node matching an XPath pattern |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static Node find(java.lang.String query, Node node) throws XPathParseException
XPath.find("child", node)
will find children,
not grandchildren.query
- XPath select pattern.node
- XML node to start searching from.public static java.util.Iterator select(java.lang.String query, Node node) throws XPathParseException
query
- XPath select pattern.node
- XML node to start searching from.public static Pattern parseSelect(java.lang.String query, NamespaceContext namespace) throws XPathParseException
XSLT uses this version of parseSelect for proper namespace matching.
query
- XPath select pattern.namespace
- the appropriate namespace mappingspublic static Pattern parseSelect(java.lang.String query) throws XPathParseException
query
- XPath select pattern.public static Pattern parseMatch(java.lang.String query, NamespaceContext namespace) throws XPathParseException
query
- XPath match pattern.namespace
- the appropriate namespace mappings.public static Pattern parseMatch(java.lang.String query) throws XPathParseException
query
- XPath match pattern.public static java.lang.String evalString(java.lang.String query, Node node) throws XPathParseException
value-of
element.
For example, to get the value of an attribute use:
String value = XPath.evalString("@id", node);
query
- XPath expressionnode
- the node contextpublic static double evalNumber(java.lang.String query, Node node) throws XPathParseException
query
- XPath expressionnode
- the node contextpublic static java.lang.Object evalObject(java.lang.String query, Node node) throws XPathParseException
query
- XPath expressionnode
- the node contextpublic static Expr parseExpr(java.lang.String query, NamespaceContext namespace, Pattern nodeList) throws XPathParseException
query
- XPath expressionnamespace
- namespace contextnodeList
- containing nodeList patternpublic static Expr parseExpr(java.lang.String query, NamespaceContext namespace) throws XPathParseException
query
- XPath expressionnamespace
- namespace contextpublic static Expr parseExpr(java.lang.String query) throws XPathParseException
query
- XPath expressionpublic static Env createEnv()
public static Env createEnv(Env global)
This lets environments share globals even through function calls.
public static void freeEnv(Env env)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |