Here you can find the source of evaluateXpath(Element from, String xpath)
Parameter | Description |
---|---|
from | Element to start the evaluation. |
xpath | Xpath expression. |
Parameter | Description |
---|---|
XPathExpressionException | if evaluation fails. |
private static NodeList evaluateXpath(Element from, String xpath) throws XPathExpressionException
//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); } }