File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes Sample on how to work with  XPATH Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Sample on how to work with  XPATH " Watch "Sample on how to work with  XPATH " New topic

Sample on how to work with XPATH

Ravi Doddi

Joined: Jan 08, 2008
Posts: 5
I have a xml file and I want to parse specific element using XPATH.
Could anyone give an sample java code that could parse an xml through XPATH.
Tushar Madhukar
Ranch Hand

Joined: May 03, 2006
Posts: 36
By "parsing" XML, I am assuming you want to query your DOM.

JDK 1.5 comes bundled with an XPath API (pl refer to package documentation of javax.xml.xpath). It is quite easy to use, with the Javadoc itself mentioning a working example.

Siegfried Heintze
Ranch Hand

Joined: Aug 11, 2000
Posts: 397

Here is the output of the embedded bash script when executed with Java 1.6 on windows with cygwin installed:

[ January 20, 2008: Message edited by: Siegfried Heintze ]
I agree. Here's the link:
subject: Sample on how to work with XPATH
It's not a secret anymore!