public final class XPathUtil extends Object
Modifier and Type | Method and Description |
---|---|
static boolean |
evalAsBoolean(String expr,
PrefixEntry[] prefixes,
XNode node,
Object[] variables)
Evaluates specified expression in the context of specified node.
|
static boolean |
evalAsBoolean(String expr,
XNode node)
Equivalent to
evalAsBoolean(expr, null, node, null) . |
static XNode[] |
evalAsNodeSet(String expr,
PrefixEntry[] prefixes,
XNode node,
Object[] variables)
Evaluates specified expression in the context of specified node.
|
static XNode[] |
evalAsNodeSet(String expr,
XNode node)
Equivalent to
evalAsNodeSet(expr, null, node, null) . |
static double |
evalAsNumber(String expr,
PrefixEntry[] prefixes,
XNode node,
Object[] variables)
Evaluates specified expression in the context of specified node.
|
static double |
evalAsNumber(String expr,
XNode node)
Equivalent to
evalAsNumber(expr, null, node, null) . |
static String |
evalAsString(String expr,
PrefixEntry[] prefixes,
XNode node,
Object[] variables)
Evaluates specified expression in the context of specified node.
|
static String |
evalAsString(String expr,
XNode node)
Equivalent to
evalAsString(expr, null, node, null) . |
static Variant |
evalAsVariant(String expr,
PrefixEntry[] prefixes,
XNode node,
Object[] variables)
Evaluates specified expression in the context of specified node.
|
static Variant |
evalAsVariant(String expr,
XNode node)
Equivalent to
evalAsVariant(expr, null, node, null) . |
static boolean |
matches(XNode node,
String pattern)
Equivalent to
matches(node, pattern, null, null) . |
static boolean |
matches(XNode node,
String pattern,
PrefixEntry[] prefixes,
Object[] variables)
Matches specified node with specified pattern.
|
static Element |
toElement(NodeIterator iter)
Returns the first node iterated by specified iterator
if this node is an element;
null otherwise. |
public static String evalAsString(String expr, XNode node) throws ParseException, EvalException
evalAsString(expr, null, node, null)
.ParseException
EvalException
public static String evalAsString(String expr, PrefixEntry[] prefixes, XNode node, Object[] variables) throws ParseException, EvalException
expr
- XPath expression to be evaluatedprefixes
- used to map prefixes to namespaces when parsing
expr.
May be null
. If null
, it is node
which is used during the parsing of expression expr
to map prefixes to namespaces.
node
- context of the evaluationvariables
- specifies the values of the variables possibly
referenced in the expression. May be null
.
This array contains variable name/variable value pairs.
A variable name may be a Name
or a plain string.
A string, which is an NCName, is automatically converted
to a Name having no namespace.
A variable value may be a Variant
or an Object.
An Object is automatically converted to a Variant using
VariantBase.create(java.lang.Object)
.
ParseException
- if expression cannot be parsedEvalException
- if parsed expression cannot be evaluatedpublic static double evalAsNumber(String expr, XNode node) throws ParseException, EvalException
evalAsNumber(expr, null, node, null)
.ParseException
EvalException
public static double evalAsNumber(String expr, PrefixEntry[] prefixes, XNode node, Object[] variables) throws ParseException, EvalException
expr
- XPath expression to be evaluatedprefixes
- used to map prefixes to namespaces when parsing
expr.
May be null
. If null
, it is node
which is used during the parsing of expression expr
to map prefixes to namespaces.
node
- context of the evaluationvariables
- specifies the values of the variables possibly
referenced in the expression. May be null
.ParseException
- if expression cannot be parsedEvalException
- if parsed expression cannot be evaluatedpublic static boolean evalAsBoolean(String expr, XNode node) throws ParseException, EvalException
evalAsBoolean(expr, null, node, null)
.ParseException
EvalException
public static boolean evalAsBoolean(String expr, PrefixEntry[] prefixes, XNode node, Object[] variables) throws ParseException, EvalException
expr
- XPath expression to be evaluatedprefixes
- used to map prefixes to namespaces when parsing
expr.
May be null
. If null
, it is node
which is used during the parsing of expression expr
to map prefixes to namespaces.
node
- context of the evaluationvariables
- specifies the values of the variables possibly
referenced in the expression. May be null
.ParseException
- if expression cannot be parsedEvalException
- if parsed expression cannot be evaluatedpublic static XNode[] evalAsNodeSet(String expr, XNode node) throws ParseException, EvalException
evalAsNodeSet(expr, null, node, null)
.ParseException
EvalException
public static XNode[] evalAsNodeSet(String expr, PrefixEntry[] prefixes, XNode node, Object[] variables) throws ParseException, EvalException
expr
- XPath expression to be evaluatedprefixes
- used to map prefixes to namespaces when parsing
expr.
May be null
. If null
, it is node
which is used during the parsing of expression expr
to map prefixes to namespaces.
node
- context of the evaluationvariables
- specifies the values of the variables possibly
referenced in the expression. May be null
.ParseException
- if expression cannot be parsedEvalException
- if parsed expression cannot be evaluatedpublic static Variant evalAsVariant(String expr, XNode node) throws ParseException, EvalException
evalAsVariant(expr, null, node, null)
.ParseException
EvalException
public static Variant evalAsVariant(String expr, PrefixEntry[] prefixes, XNode node, Object[] variables) throws ParseException, EvalException
expr
- XPath expression to be evaluatedprefixes
- used to map prefixes to namespaces when parsing
expr.
May be null
. If null
, it is node
which is used during the parsing of expression expr
to map prefixes to namespaces.
node
- context of the evaluationvariables
- specifies the values of the variables possibly
referenced in the expression. May be null
.ParseException
- if expression cannot be parsedEvalException
- if parsed expression cannot be evaluatedpublic static boolean matches(XNode node, String pattern) throws ParseException, EvalException
matches(node, pattern, null, null)
.ParseException
EvalException
public static boolean matches(XNode node, String pattern, PrefixEntry[] prefixes, Object[] variables) throws ParseException, EvalException
node
- node to be matchedpattern
- XPath pattern
(subset of XPath expressions;
see XSLT)
used to match node nodeprefixes
- used to map prefixes to namespaces when parsing
pattern.
May be null
. If null
, it is node
which is used during the parsing of pattern pattern
to map prefixes to namespaces.
variables
- specifies the values of the variables possibly
referenced in the pattern. May be null
.true
if node matches; false
otherwiseParseException
- if pattern cannot be parsedEvalException
- if an XPath problem occurs during the
operationpublic static Element toElement(NodeIterator iter)
null
otherwise.
This utility method is useful to write XPath extension functions.