| Author |
Learning XML DOM parser
|
shuba gopal
Ranch Hand
Joined: May 12, 2011
Posts: 76
|
|
Hi I am trying to read the following XML file
The getNodeName() method returns Node name correctly as testdata but My problem is that the NodeList method getLength() is 0 when it should be populated with the number of "user id"s
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12268
|
|
It is NOT legal XML to have an element name with a space like your "user id".
Other name limitations:
can't start with "xml"
can't start with a number
can't contain the # character
Bill
|
Java Resources at www.wbrogden.com
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
That's a well-formed document. Those are "user" elements with "id" attributes.
(So searching for a "user id" element is the incorrect part.)
|
 |
shuba gopal
Ranch Hand
Joined: May 12, 2011
Posts: 76
|
|
I am actually planning to sort the id values by populating them in a TreeSet. But I am not able to do it this way. Is there anything wrong with using the getElementsByTagName() method? I tried using just "id" but that doesnt work either. Is there any other approach to get the id value?
Thanks
Shuba
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
It would help if you spent a few minutes learning about XML, so that for example you could tell the difference between an element and an attribute. (Here's a good on-line book to start with: http://www.cafeconleche.org/books/xmljava/.) If you don't even know that much then trying to write code is not going to be practical.
Hopefully after you have done that you will understand what you are looking for in your document and be able to figure out how to find it. Right now you are just programming by making guesses, which isn't a practical method either.
|
 |
 |
|
|
subject: Learning XML DOM parser
|
|
|