Here you can find the source of getValueFromXPath(Document document, String xpathString)
Parameter | Description |
---|---|
document | - XML Document to check |
xpathString | - xpath to evaluate |
public static String getValueFromXPath(Document document, String xpathString)
//package com.java2s; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; import org.w3c.dom.Document; public class Main { /***//from w w w. ja v a 2s . c om * Returns the string value of evaluated xpath * * @param document - XML Document to check * @param xpathString - xpath to evaluate * @return String evaluation of the xpath */ public static String getValueFromXPath(Document document, String xpathString) { try { return (String) XPathFactory.newInstance().newXPath().evaluate(xpathString, document, XPathConstants.STRING); } catch (XPathExpressionException e) { throw new RuntimeException("Error evaluating xpath [" + xpathString + "] -- " + e.getMessage()); } } }