Java XPath

Quick way to extract data from XML is XPath.

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;

String xmlData = "place the XML Data here.";
XPath xpath = XPathFactory.newInstance().newXPath();
InputStream inStream = new ByteArrayInputStream(xmlData.getBytes());
InputSource inputSource = new InputSource(inStream);
String nodeValue = xpath.evaluate("//nodeName", inputSource);
System.out.println("nodeValue==>" + nodeValue);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s