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?
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.