Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

Transform DOM to TableModel

Thread view: 
Larry Coon - 18 Nov 2005 15:45 GMT
I'm writing an application which will invoke a servlet (via a
UrlConnection) and display the (CML) data returned by the servlet
in a JTable.  (The data returned by this servlet is in row/column
format, so in this application a JTable is the appropriate control
for displaying the data.)  Can someone give me advice on the best
approach for converting a DOM to a TableModel:

-- Write a Transformer that takes a Document as a source and
  uses a TableModel as a sink?

-- Use XSLT?

-- Use SAX instead of DOM (I'm not married to DOM) and build
  the TableModel as thx SAX parser parses it?

Any advice would be appreciated.

Larry Coon
University of California
pit.grinja@gmx.de - 18 Nov 2005 18:52 GMT
Hi Larry,
>I'm writing an application which will invoke a servlet (via a
>UrlConnection) and display the (CML) data returned by the servlet
>in a JTable.  (The data returned by this servlet is in row/column
>format, so in this application a JTable is the appropriate control
>for displaying the data.)  Can someone give me advice on the best
>approach for converting a DOM to a TableModel.
Are we dealing with a DOM tree or a table? I believe that your XML data
has a structure which was designed to represent tabular data.
>-- Write a Transformer that takes a Document as a source and
>   uses a TableModel as a sink?
I would insert one more step: extract the data that you want from your
DOM and convert that into a 2 dimensional data structure (Arraylist of
arraylists or a 2D object[][])and then warp a TableModel around that
data structure. That will make the implementation of the TableModel
easier than directly accessing the DOM. Furthermore, the memory-hungry
DOM will probably not gc`ed when it is referenced from within the
TableModel.
>-- Use XSLT?
No. You still would have to wrap your TableModel around the data that
result from the transformation.
>-- Use SAX instead of DOM (I'm not married to DOM) and build
>   the TableModel as thx SAX parser parses it?
Since your data seem to have a rather flat, 2D like structure, SAX
could be the better choice here, indeed. Personally, I have never used
SAX before (DOM always seemd to be the solution with the lesser
headaches), but SAX is "leaner". So when you have to deal with huge
files with a simple structure that won´t change from file to file, SAX
is the way to go. As outlined above, its probably easier to first build
a separate 2D data structure from your SAX events, and when this is
done, wrap your TableModel around your data. Or, if you really want to
experiment, connect the SAX parser somehow to your tablemodel, and
whenever the SAX Parser fires an event, make the TableModel fire a
suitable event to notify the JTable about the event, and watch how the
JTable is build up "life" (forget about this last suggestion in a
production environment).
HTH
Piet
Larry Coon - 23 Nov 2005 16:51 GMT
> I would insert one more step: extract the data that you want from your
> DOM and convert that into a 2 dimensional data structure (Arraylist of
[quoted text clipped - 3 lines]
> DOM will probably not gc`ed when it is referenced from within the
> TableModel.

Hi Piet,

Thanks for the advice.  This is what I ended up doing, and it worked
great.

Larry Coon
University of California

The NBA Salary Cap FAQ:
http://members.cox.net/lmcoon/salarycap.htm


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.