• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to get the value of a tag in xml using java  RSS feed

 
Raaja Gotluru
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am having an xml like below

I want the values of tags servername and theatername. Rest I dont want. How to get these using java. Is it possible to get the value using tagnames.

Thanks.

--raaja.g
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use XPath for that; both the interface and more generally the technique.
 
Raaja Gotluru
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. The problem is solved. I used dom parser to acieve this.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you use a NodeList bookslist and not just doc.getDocumentElement()? Other than that, and the lack of error checking, that code looks decent.
 
John Jai
Rancher
Posts: 1776
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont know if XPath is more proficient but looks more readable. please use code tag henceforth.
 
Raaja Gotluru
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for the reply. But the problem is how to get the root node at run time. Because the root node differes from xml to xml. Only servername and theatername are common.
If I use

xmlData += (xpath.evaluate("/Movies/servername", doc.getDocumentElement())).trim();

it will give problem as the root node differs.

Can we get the root node at run time. Please guide me.

Thanking you.

--raaja.g
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what's being returned by doc.getDocumentElement(). Each XML document has only one single root element. Here it's called the document element.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!