public final class XPathUtils extends Object
javax.xml.xpath.XPath#evaluate(String, Object,
QName).| Modifier and Type | Method and Description |
|---|---|
static <T> T |
evaluate(String xpath,
Node contextNode,
Map<String,String> namespaceMap,
Class<T> expectedType)
Evaluates an XPath expression over a DOM node and casts the result to a
Java type.
|
static Object |
evaluate(String xpath,
Node contextNode,
Map<String,String> namespaceMap,
QName returnType)
Evaluates an XPath expression over a DOM node.
|
static int |
getCount(String xpath,
Node contextNode,
Map<String,String> namespaceMap)
Evaluates an XPath expression over a DOM node and returns the count of DOM
nodes that the expression evaluated to.
|
static List<Element> |
getElementList(String xpath,
Node contextNode,
Map<String,String> namespaceMap)
Evaluates an XPath expression to a list of Elements.
|
public static <T> T evaluate(String xpath, Node contextNode, Map<String,String> namespaceMap, Class<T> expectedType) throws XPathExpressionException
T - Java typexpath - XPath expression to evaluate. Cannot be null nor an empty string.contextNode - DOM node to evaluate XPath over. Cannot be null.namespaceMap - Mapping of namespace prefixes in XPath expression to namespace
URIs.expectedType - The Java type to cast the result object to. Cannot be null.
Possible values are: java.lang.String.class (for a string value),
java.lang.Boolean.class (for a boolean value),
java.lang.Double.class (for a number value), org.w3c.dom.NodeList
(for a node set), org.w3c.dom.Node (for a node value) or
sub-classes of org.w3c.dom.Node (such as a DOM element).XPathExpressionException - Thrown when the XPath expression cannot be evaluated.public static Object evaluate(String xpath, Node contextNode, Map<String,String> namespaceMap, QName returnType) throws XPathExpressionException
xpath - XPath expression to evaluate. Cannot be null nor an empty string.contextNode - DOM node to evaluate XPath over. Cannot be null.namespaceMap - Mapping of namespace prefixes in XPath expression to namespace
URIs.returnType - Expected type of result object. Cannot be null. The value must
come from the XPathConstants class.XPathExpressionException - Thrown when the XPath expression cannot be evaluated.public static int getCount(String xpath, Node contextNode, Map<String,String> namespaceMap) throws XPathExpressionException
xpath - XPath expression to evaluate. Cannot be null nor an empty string.contextNode - DOM node to evaluate XPath over. Cannot be null.namespaceMap - Mapping of namespace prefixes in XPath expression to namespace
URIs.XPathExpressionException - Thrown when the XPath expression cannot be evaluated.public static List<Element> getElementList(String xpath, Node contextNode, Map<String,String> namespaceMap) throws XPathExpressionException
xpath - XPath expression to evaluate. Cannot be null nor an empty string.contextNode - DOM node to evaluate XPath over. Cannot be null.namespaceMap - Mapping of namespace prefixes in XPath expression to namespace
URIs.XPathExpressionException - Thrown when the XPath expression cannot be evaluated.Copyright © 2021. All rights reserved.