Lists Home |
Date Index |
"Fang, Frank" <Frank.Fang@ap.bdi.gte.com>
07/01/2002 04:41 PM
To: "'firstname.lastname@example.org'" <email@example.com>
Subject: [xml-dev] From JTree to DOM or XML
is there anyone happen to have experience or have knowledge about how to
convert a JTree to DOM or xml, I know a lot of stuff about from DOM to
JTree, I do need to construct a DOM from JTree then send to backend, then
get an returned XML back from backend , display as Jtree
I don't know of any way to go directly from a JTree to an XML
representation. I think you will need to work with the TreeModel.
Get the TreeModel from the JTree.
Get the root object from the TreeModel.
Start the DOM Document with DOMImplementation.createDocument().
Then recursively process the TreeModel root's child(ren), using
getChildCount() and getChild().
That should work if the TreeModel and the DOM are the same
structure (in parent-child terms) and all JTree Nodes are DOM
Nodes. You have to handle any other cases as your app requires.
If you build your own TreeModel, you could build "TreeModel to
DOM" conversion into it. It would make the code a little cleaner at
the higher level.
Sun has DOM to JTree on their site in a Java XML tutorial.
Part III is "XML and the Document Object Model (DOM)" at
It includes a section, "Constructing a User-Friendly JTree from a DOM"
in that Part III.