How to read XML using XPath in Java

Posted by kaibuki on Stack Overflow See other posts from Stack Overflow or by kaibuki
Published on 2010-05-11T13:21:18Z Indexed on 2010/05/11 13:24 UTC
Read the original article Hit count: 295

Filed under:
|
|
|

Hi guys,

I want to read XML data using XPath in Java, so for the information I have gathered I am not able to parse XML according to my requirement.

here is what I want to do:

Get XML file from online via its URL, then use XPath to parse it, I want to create two methods in it. One is in which I enter a specific node attribute id, and I get all the child nodes as result, and second is suppose I just want to get a specific child node value only

<?xml version="1.0"?><howto>  <topic name="Java">      <url>http://www.rgagnonjavahowto.htm</url>   <car>taxi</car>  </topic>  <topic ame="PowerBuilder">      <url>http://www.rgagnon/pbhowto.htm</url>      <url>http://www.rgagnon/pbhowtonew.htm</url>  </topic>  <topic name="Javascript">        <url>http://www.rgagnon/jshowto.htm</url>  </topic>  <topic name="VBScript">       <url>http://www.rgagnon/vbshowto.htm</url>  </topic></howto>

In above example I want to read all the elements if I search via @name and also one function in which I just want the url from @name 'Javascript' only return one node element.

I hope I cleared my question :)

Thanks.

Kai

© Stack Overflow or respective owner

Related posts about xpath

Related posts about Xml