[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: From JTree to DOM or XML
"Fang, Frank" <Frank.Fang@a...> 07/01/2002 04:41 PM To: "'xml-dev@l...'" <xml-dev@l...> cc: Subject: 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 Thanks Frank Hi, 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. http://java.sun.com/xml/jaxp/dist/1.1/docs/tutorial/TOC.html Part III is "XML and the Document Object Model (DOM)" at http://192.18.97.71/xml/jaxp/dist/1.1/docs/tutorial/dom/index.html It includes a section, "Constructing a User-Friendly JTree from a DOM" in that Part III. HTH, Joe
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|