Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

What's a good way to show attributes in a JTree made from DOM?

800160Nov 23 2010 — edited Nov 23 2010
I'm doing a pretty simple project that's basically just taking an XML document, making a DOM out of it, and then I want to represent the document in a JTree. The code I have now works swimmingly, except it doesn't do anything about attributes. Ideally (for the purposes of the tree), I'd like the attributes to show up as children of the node of which they are an attribute, and then each attribute node would itself have a child representing the value.

basically I want to go from this:
<xmlNode attribute=value>
   <child>
   </child>
</xmlNode>
To a JTree like this ('v' being the expansion arrow on the tree):
v xmlNode
   v attribute
      v value
   v child
I realize they're not of equivalent meaning, but for my purposes representing the true structure of the XML is not as important as meaningfully representing the information it contains.

My question is basically, is there a more straightforward way to accomplish this than to manually add children nodes for all of the attributes? How would you approach this problem? I'm not looking for code or for someone to give me the "answer," I just wanted to get a second opinion.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 21 2010
Added on Nov 23 2010
3 comments
215 views