Java Utililty Methods XPath Evaluate

List of utility methods to do XPath Evaluate

Description

The list of methods to do XPath Evaluate are organized into topic(s).

Method

StringevaluateXPath(Node node, String xPath)
evaluate X Path
int currentSearchIndex = 0;
while (currentSearchIndex < xPath.length()) {
    int endingIndex = xPath.indexOf("/", currentSearchIndex);
    String noderNameFromXPath = null;
    if (endingIndex == -1) {
        noderNameFromXPath = xPath.substring(currentSearchIndex);
    } else {
        noderNameFromXPath = xPath.substring(currentSearchIndex, endingIndex);
...
TevaluateXpath(String expression, Document document, QName dataType)
evaluate Xpath
try {
    XPath xpath = createXPath();
    XPathExpression compiledExpression = xpath.compile(expression);
    return (T) compiledExpression.evaluate(document, dataType);
} catch (XPathExpressionException e) {
    throw new IllegalArgumentException("Cannot evaluate XPath expression '" + expression + "'");
ObjectevaluateXpath(String expression, Object node, QName returnType, NamespaceContext nsContext)
evaluate Xpath
XPathFactory xpathFactory = XPathFactory.newInstance();
XPath xpath = xpathFactory.newXPath();
if (nsContext != null) {
    xpath.setNamespaceContext(nsContext);
return xpath.evaluate(expression, node, returnType);
ObjectevaluateXPath(String path, Node e, QName type)
evaluate X Path
try {
    XPathExpression expr = compiledString.get(path);
    if (expr == null) {
        expr = xpath.compile(path);
        compiledString.put(path, expr);
    return expr.evaluate(e, type);
} catch (XPathExpressionException e1) {
...
ObjectevaluateXPath(String xpath, Object item, QName returnType)
evaluate X Path
try {
    return XPathFactory.newInstance().newXPath().compile(xpath).evaluate(item, returnType);
} catch (XPathExpressionException e) {
    throw new IllegalArgumentException(e);
NodeListevaluateXPathAsNodeList(String expression, Document document)
Returns the XML NodeList matching the given XPath expression.
return evaluateXpath(expression, document, XPathConstants.NODESET);
booleanevaluateXPathBool(final Node inNode, final String xpath)
evaluate X Path Bool
Boolean xPathBool = (Boolean) getNodesListXpath(xpath, inNode, "", "", XPathConstants.BOOLEAN);
return xPathBool.booleanValue();
ObjectevaluateXPathExpr(final File xmlFile, final XPathExpression xPathExpression, final QName returnType)
Evaluates the passed XPathExpression against the Document created out of the passed xmlFile and returns the result of the evaluation.
if (xmlFile == null) {
    throw new IllegalArgumentException("XML file cannot be null");
if (!xmlFile.isFile()) {
    throw new IllegalArgumentException(xmlFile + " is either missing or not a file");
if (xPathExpression == null) {
    throw new IllegalArgumentException("XPath expression cannot be null");
...
NodeListevaluateXPathExpr(XPathExpression xpath, Node node)
evaluate X Path Expr
return (NodeList) xpath.evaluate(node, XPathConstants.NODESET);
NodeListevaluateXPathExpression(final String expression, final Node node)
Evaluate XPath expression and return list of nodes.
return (NodeList) evaluateXPathExpression(expression, node, XPathConstants.NODESET);