Here you can find the source of extractNode(XPath xpath, String nodePath, String xmlString)
Parameter | Description |
---|---|
xpath | XPath object |
nodePath | XPath statement to locate the node |
xmlString | Xml string object to extract the data from |
public static String extractNode(XPath xpath, String nodePath, String xmlString)
//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 { /**//from w w w . j av a2 s . c o m * 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 ""; } } }