Home > XML > Java XPath

Java XPath

Quick way to extract data from XML is XPath.

http://www.whitebeam.org/library/guide/TechNotes/xpathtestbed.rhtm

http://www.whitebeam.org/library/guide/TechNotes/xpath.rhtm

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;
import java.io.*;

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);

Advertisement
Categories: XML Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

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

Gravatar
WordPress.com Logo

You are commenting using your WordPress.com account. 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 )

Connecting to %s

Follow

Get every new post delivered to your Inbox.