The other issue consider when looking at DOM vs SAX is that SAX is a “firehose” model.  Once you’ve visited an element, you can’t get it back, unless you cache your own version of it.  If you are going to do a lot of that, you should just use DOM.  DOM lets you easily “walk” the tree structure, create/maintain individual or lists of node references, etc.  If you only want to process each element once, then throw it all away, then SAX provides much better performance.

 


From: Phil Weighill-Smith [mailto:[EMAIL PROTECTED]
Sent: Friday, August 27, 2004 2:09 AM
To: [EMAIL PROTECTED]
Subject: Re: SV: Reading entire tree structure of an XML

 

As Martin indicated, the choice of DOM vs SAX is commonly because of the overall expected data set size rather than the number of levels of nesting.

If you've got an XML application that contains just a "few" complex entries then DOM is probably reasonable. If however you expect a lot of complex entries and are worried about performance issues (because of memory issues) then use SAX.

Again, as Martin suggests, you can use SAX to build fragments of your data set (e.g. so you process a single complex entry at a time). By writing your SAX ContentHandler to actually generate the required DOM nodes you can even "fool" the rest of your application into thinking it is working with normal DOMs that happen to only contain a single complex entry at a time (for example).

Phil :n)

On Fri, 2004-08-27 at 08:25, [EMAIL PROTECTED] wrote:

Hi Martin,

Actually i have nested elements which sometimes go upto 4 levels of nesting. Is it still advisable to go in for SAX or
is it definitely DOM in this case ?



Thanks,

Chetan Arora



Martin Gülich <[EMAIL PROTECTED]>

08/27/2004 12:43 PM

Please respond to

 

[EMAIL PROTECTED]

To

<[EMAIL PROTECTED]>

cc

 

Subject

SV: Reading entire tree structure of an XML

 

 

 




Hi!
Use DOM parsing! But if you have a large file it might be inefficient, then SAX parsing is better. If you only want to handle ONE entire element at a time you can build your own tree structure for that element only by using a stack or something similar. Then discard the tree and build a new for the next element etc.
 
Martin Gülich
Research Engineer
______________________________

Swedish Defence Research Agency
Dept. Of Systems Modelling
SE-172 90 Stockholm, Sweden

Phone: +46 8 55503691
Company web site:
www.foi.se
 
-----Ursprungligt meddelande-----
Från: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Skickat: den 27 augusti 2004 06:49
Till: [EMAIL PROTECTED]
Ämne: Reading entire tree structure of an XML

 

Hi,



My XML has atleast 5 levels of nested elements. How can i read the entire data and put
it in a Container so that i can use that data for processing ?



Thanks and Regards,

Chetan

ForwardSourceID:NT00002892    


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

--
Phil Weighill-Smith <[EMAIL PROTECTED]>
Volantis Systems

 

Reply via email to