• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

getting the value of a node

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I'm new to XML. I was going through Sun's tutorial and trying to parse a XML document using JAXP. This is my XML file.


This is how i'm trying to parse it

When i run the program, It does print the name of child node but doesn't print their value. Could someone please let me know how to fix it. Thanks for your time
 
Sheriff
Posts: 28328
96
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a look at the API documentation for org.w3c.dom.Node and you will see a table that tells you what to expect as "name" and "value" for every type of node. You'll see, for example, that an Element node has a name (what you would expect) but it doesn't have a value.

What you have in your example XML is a bunch of Elements, and some of them have Text nodes as children. Don't expect that asking for the value of an Element will return the value of one or any or all of its child nodes. If you want the value of the Text node that's a child of an Element node, you have to write the code to get the Text node and ask for its value.
 
Why fit in when you were born to stand out? - Seuss. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic