Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading attribute values of Element

 
ravindra patil
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Dont know where to put this question .

anyways i have xml like this

<Root>
<elemt1>
<x name="NONAME" />
<x name="NONAME1" />
<x name="NONAME2" />
<x name="NONAME2" />
</elemt1>
</Root>
here i want to read values of attribute name using XPath , i want to check for duplicate names so want all values of name attribute

-ravi
 
Anayonkar Shivalkar
Bartender
Posts: 1557
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ravindra patil wrote:Dont know where to put this question .

How about this?
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can get the list of NodeList of "x" nodes and read its "name" attribute. Check XPath and its evaluate() method.

Google sample codes for doing XPath operations.
 
Paul Clapham
Sheriff
Posts: 21319
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The XPath expression for those attribute nodes is
/Root/elemt1/x/@name

But do you have a question? So far you have only said what you want to do. So, go ahead and do it. Of course if you do have a question, then as you can see there are people here who are happy to answer questions.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic