[jdom-interest] When to use SAXBuilder or DOMBuilder?
Alex Rosen
arosen at silverstream.com
Tue Jul 2 07:24:27 PDT 2002
I think SAXBuilder and DOMBuilder are confusingly named. SAXBuilder converts
an XML file into a JDOM tree (and it happens to do this using SAX).
DOMBuilder converts a DOM tree into a JDOM tree. So if you've already got a
DOM tree, use DOMBuilder, otherwise use SAXBuilder.
I think the DOM vs. SAX rules that you mention are really tree vs. no-tree
rules. DOM and JDOM are both tree representations of XML - you parse the
file into a tree, and then you can navigate all around the tree as much as
you want. It's easy, but it must load the whole file into memory. Using SAX
w/o DOM or JDOM can use less memory if you do it right, but it's confusing
to do.
Alex
-----Original Message-----
From: jdom-interest-admin at jdom.org [mailto:jdom-interest-admin at jdom.org]On
Behalf Of Duffey, Keven
Sent: Monday, July 01, 2002 12:19 AM
To: jdom-interest at jdom.org
Subject: [jdom-interest] When to use SAXBuilder or DOMBuilder?
Hi all,
My application allows for a number of selected XML files. It then loops
through each file, getting "part" of the XML data, displaying it, having
some user interaction, then getting another part of the XML data, and
storing it into a DB along with the user selections take from the first
part. Right now I am using SAXBuilder to do this. I thought I read a while
ago that SAX is great for a one time loop through the XML file, but if you
frequently get the root document in different methods, then it is not good
and DOM is the way to go. I also read that DOM is much more memory
intensive, whereas SAX uses very little memory and reads the XML much
faster. I need to keep memory to a VERY low as our app will run on machines
with 32MB RAM and Windows on it!
To detail a bit more, my app allows a pluggable "format" system. Each plugin
implements how it gets "header" data out of the XML file. That header data
is then used to be displayed and allow the user to match it up to other DB
related items. Then, after that, the next step is to parse a large chunk of
the same XML file, using parts of the user interacted selections and store
it all in our own format in the DB. This is like a SPOKE program where our
program accepts various types of formats, converting each to our own generic
format and storing it. Since it is possible that hundreds of files could be
selected at one time, and I loop through each file, I figured SAX would be
the way to go to avoid the memory overhead. However, since there are two
parts to the parsing of the same one XML file, what I have done is stored a
ref of the XML file that is parsed for the header data, then later on when
the GUI allows, a different method of the same XML parsing class uses the
already loaded SAXBuilder ref to that XML file. That method also gets the
root, and so on. So is SAX the best way to go, or should I replace this with
DOMBuilder?
Thanks.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: winmail.dat
Type: application/ms-tnef
Size: 6464 bytes
Desc: not available
Url : http://jdom.org/pipermail/jdom-interest/attachments/20020702/a06c7d38/winmail.bin
More information about the jdom-interest
mailing list