Here you can find the source of getValueByXpath(Node doc, String xquery)
public static String getValueByXpath(Node doc, String xquery)
//package com.java2s; //License from project: Apache License import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathFactory; import org.w3c.dom.Node; public class Main { public static String getValueByXpath(Node doc, String xquery) { try {//w w w.j ava 2 s . com XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); XPathExpression expression = xpath.compile(xquery); String result = (String) expression.evaluate(doc, XPathConstants.STRING); return result; } catch (Exception e) { } return null; } }