Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes Writing / reading JTree to/from xml / html file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Writing / reading JTree to/from xml / html file" Watch "Writing / reading JTree to/from xml / html file" New topic
Author

Writing / reading JTree to/from xml / html file

John Vorwald
Ranch Hand

Joined: Sep 26, 2010
Posts: 139
Hello,

I need some help in writing / reading a jtree to a binary file and also to an html file.

A program uses a jtree to create / investigate structural modifications to an analytical model. As the program runs, the various perturbations of the analytical model are added to the tree, and the perturbations evaluated with summary performance results stored in the tree, and the more successful performing leafs are explored / expanded further. I need to write the jtree data to a file as additional leafs are added to the tree, and then read in a previously written tree when the program restarts.

I can probably implement a tree traversal and write out either a binary or text representation of the tree, but haven't done this before, so any suggestions on writing / reading a jtree to a file would be appreciated.

Also, it would be advantageous to write out an html file of the tree structure that could be viewed using a browser so the progress / solution could be investigated while the program continues to run.

Each leaf of the tree holds quite a bit of data that defines a model topology (inputs, outputs, model structure, number of submodels, etc) and also contains summary performance data of the submodels. The submodels of a leaf are essentially trivial variations of the leaf's model.

This program will run for a long time, think years, and essentially continuously evaluate / optimize the model structures as new data becomes available. There will probably be times when the evolution of the performance of optimal model structures is reviewed, so a "archival" copy of the current tree should be written out at some interval, like every two weeks, and also whenever model results are utilized (random intervals).
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12754
    
    5
According to the javax.swing.JTree JavaDocs, serializing a JTree is only recommended for short term use and points to java.beans.XMLEncoder for the preferred way of storage.

I would certainly look into XMLEncoder.

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Writing / reading JTree to/from xml / html file
 
Similar Threads
JTree Scalablity ???
Can't display new JTree after GUI up
JTree / DataModel Confusion
JTree errors with treeModel.nodeChanged()
Jtree child selection problem