Java XPath Evaluate evaluateXpath(Element from, String xpath)

Here you can find the source of evaluateXpath(Element from, String xpath)

Description

Evaluates an Xpath expression and return its result as a NodeList.

License

BSD License

Parameter

Parameter Description
from Element to start the evaluation.
xpath Xpath expression.

Exception

Parameter Description
XPathExpressionException if evaluation fails.

Return

Result of evaluation as a NodeList.

Declaration

private static NodeList evaluateXpath(Element from, String xpath)
        throws XPathExpressionException 

Method Source Code

//package com.java2s;
/*//from w  w  w  .  jav a2s.  c  om
 * This file is released under terms of BSD license
 * See LICENSE file for more information
 */

import org.w3c.dom.Element;

import org.w3c.dom.NodeList;

import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

public class Main {
    /**
     * Evaluates an Xpath expression and return its result as a NodeList.
     *
     * @param from  Element to start the evaluation.
     * @param xpath Xpath expression.
     * @return Result of evaluation as a NodeList.
     * @throws XPathExpressionException if evaluation fails.
     */
    private static NodeList evaluateXpath(Element from, String xpath)
            throws XPathExpressionException {
        XPathExpression ex = XPathFactory.newInstance().newXPath()
                .compile(xpath);
        return (NodeList) ex.evaluate(from, XPathConstants.NODESET);
    }
}

Related

  1. evaluateNodeListXPath(final Document document, final String expression)
  2. evaluateNodes(final XPathExpression xpathExpression, final Document pom)
  3. evaluateNodeSet(XPathExpression xpe, Object item)
  4. evaluateXpath(Document doc, String xpath, QName returnType)
  5. evaluateXPath(Element element, String xpathstring)
  6. evaluateXPath(final String xPath, final Object item, final QName returnType)
  7. evaluateXPath(final XPathExpression expr, final Object rootNode, final QName returnType)
  8. evaluateXPath(Node node, String xPath)
  9. evaluateXpath(String expression, Document document, QName dataType)