Java tutorial
//package com.java2s; //License from project: Apache License import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import javax.xml.xpath.XPath; public class Main { private static XPath xPath; public static String getXmlString(Node inXml, String xpath) { if (!xpath.contains("/")) { NodeList elements = ((Element) inXml).getElementsByTagName(xpath); if (elements.getLength() == 1) { return elements.item(0).getTextContent(); } } try { return xPath.evaluate(xpath, inXml); } catch (Exception ex) { throw new RuntimeException("Could not run xpath: " + xpath, ex); } } }