Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Printing values from a xml file

 
zahid zubair
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am a novice in xml. I am using jdk1.4. I need some idea on how to parse XML file using DOM Parser.

I have a file with the following contents:


Basically I want to iterate though the file using a DOM parser and bring the results back to my Java code. Currently, I have:


Can anyone please tell me why the value of the node 'Zahid Zubair' is not getting printed?


Thanks,
Zahid
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your assumption about how the DOM tree is structured is incorrect. You may want to print out the type and name of the node you're inspecting.
 
zahid zubair
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ulf,

I hope this would be correct structure:



Please let me know what I am missing here:
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's the XML structure; but the DOM tree structure is different than what you think it is. I suggest you iterate through the entire node list and print out node names, types and values. You should also consult the javadocs of the Node interface in order to learn what values nodes have for the various node types.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic