wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes Learning XML DOM parser 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 "Learning XML DOM parser" Watch "Learning XML DOM parser" New topic
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: 12761
    
    5
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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: 18541
    
    8

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
 
Similar Threads
help with web service to display xml file contents using netbeans
JAXB Marshalling, setter methods problem
Data not get displayed in struts2 - jquery grid
XML generation pbm with JAXB Marshaler
Showing database rows as columns