• 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
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

XML DOM & children nodes

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am parsing a simple xml document using dom and attempting to display the data in a JTree which will eliminate and group the node data together at the parent node level.
the basis for my code is from the java tutorial http://java.sun.com/xml/jaxp/dist/1.1/docs/tutorial/ with the following modifications to the AdapterNode toString() method:

my xml document has the following basic structure:

the JTree looks like this:

so, given a [group] node which must have [name] and [id] children and optionally a [groups] node for further nesting. however, since the level of detail shown in the JTree is unnecessary for me (all i want is the [group] entry with the nodeValues of it's children who are not a node of name [groups]). so ideally, my JTree should look like:

etc...
the problem is that when i take the parent node ([group]) and getChildNodes(), i can invoke on a node of that list, node.getNodeName() and it will return the proper name of the node. however, if i invoke node.getNodeValue() on the same parent, it returns a null value, despite the fact that when you expand the JTree, the specified nodes and values are present.
sorry for the long message. any ideas anyone?
 
author & internet detective
Posts: 42151
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Elements return null for nodeValue(). For that matter, so does everything except attributes, CDATA, comments, processing instructions and text.
You have to get the attributes for the parent node or loop through its children to get any useful info.
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to the XML forum.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a VERY handy table in the org.w3c.dom.Node JavaDocs that shows what is returned for nodeName and nodeValue for all types of nodes. That null return trips up a lot of people.
Bill
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic