This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Reading attribute values of Element 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 "Reading attribute values of Element " Watch "Reading attribute values of Element " New topic
Author

Reading attribute values of Element

ravindra patil
Ranch Hand

Joined: Sep 01, 2006
Posts: 234


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

Joined: Dec 08, 2010
Posts: 1541
    
    5

ravindra patil wrote:Dont know where to put this question .

How about this?


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
John Jai
Rancher

Joined: May 31, 2011
Posts: 1776
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

Joined: Oct 14, 2005
Posts: 19719
    
  10

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading attribute values of Element
 
It's not a secret anymore!