aspose file tools*
The moose likes XML and Related Technologies and the fly likes Element with same name Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Element with same name" Watch "Element with same name" New topic
Author

Element with same name

Dalia Sultana
Ranch Hand

Joined: Jul 16, 2006
Posts: 42
Hi,

I am trying to store the application preferences in an xml file. I am aiming for a structure like this for a JTable for which users can change the list of columns that are displayable.

<table_test>
<columns>
<column name ="col 1" width ="100">
<column name = "col 2" width ="150">
</columns>
</table_test>

- but when I read the file using a DOM parser, my columns element contains only the 'col 2' entry. I can understand that this is happening because the child elements have the same name 'column'. How can I get around this problem. The columns node can have different number of entries at different point of time.

Please help!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Originally posted by Dalia Sultana:
when I read the file using a DOM parser, my columns element contains only the 'col 2' entry. I can understand that this is happening because the child elements have the same name 'column'.
No, you understand incorrectly. The DOM parser will produce a structure that contains all of the "column" elements. It's then up to you to write code that extracts them all, and I expect you didn't do that correctly.

So have another look at your code. Post it here if you are still having problems extracting the data in the way you want.
[ July 31, 2007: Message edited by: Paul Clapham ]
Dalia Sultana
Ranch Hand

Joined: Jul 16, 2006
Posts: 42
You are right. Thank you.
 
 
subject: Element with same name