[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: From JTree to DOM or XML


jtree 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!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.