This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
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

Win a copy of Building Microservices this week in the Design forum!
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: 396

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 ]
Have you checked out Aspose?
subject: Sample on how to work with XPATH
It's not a secret anymore!