Java tutorial
//package com.java2s; //License from project: Open Source License import org.xml.sax.InputSource; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpressionException; import java.io.StringReader; public class Main { /** * Extract a String node from an XML Message * * @param xpath XPath object * @param nodePath XPath statement to locate the node * @param xmlString Xml string object to extract the data from * @return The requested data, or "" if not found. */ public static String extractNode(XPath xpath, String nodePath, String xmlString) { InputSource inputSource = new InputSource(new StringReader(xmlString)); try { return (String) xpath.evaluate(nodePath, inputSource, XPathConstants.STRING); } catch (XPathExpressionException e) { return ""; } } }