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.