Here you can find the source of getXPathItemText(Document doc, XPath xpath, String query)
public static String getXPathItemText(Document doc, XPath xpath, String query) throws XPathExpressionException
//package com.java2s; //License from project: Apache License import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpressionException; import org.w3c.dom.Document; import org.w3c.dom.Node; public class Main { public static String getXPathItemText(Document doc, XPath xpath, String query) throws XPathExpressionException { if (doc == null || xpath == null || query == null) { return null; }//w w w .j a v a 2 s .co m Node node = (Node) xpath.evaluate(query, doc, XPathConstants.NODE); String text = null; if (node != null) { text = node.getNodeValue(); if (text != null) { text = text.trim(); } } return text; } }