• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Learning XML DOM parser

 
shuba gopal
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Paul Clapham
Sheriff
Pie
Posts: 20979
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20979
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic