OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] From JTree to DOM or XML

[ Lists Home | Date Index | Thread Index ]

"Fang, Frank" <Frank.Fang@ap.bdi.gte.com>
07/01/2002 04:41 PM

 
        To:     "'xml-dev@lists.xml.org'" <xml-dev@lists.xml.org>
        cc: 
        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
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





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS