File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Product and Other Certifications and the fly likes differences between DOM and SAX parser? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Product and Other Certifications
Bookmark "differences between DOM and SAX parser?" Watch "differences between DOM and SAX parser?" New topic

differences between DOM and SAX parser?

Sudhakar Reddy Kurakula
Ranch Hand

Joined: Aug 19, 2006
Posts: 42
Please give me answer.
Kaise a.Zakkar
Ranch Hand

Joined: Oct 20, 2003
Posts: 47
Well Dear Sudhakar
the main deffenence between those two techniques in parsing XML documents are
the following:
1- if you are working on some critical performance issues like time and storage , you should go for the SAX,but why...
well , SAX Api depends on what i used to call afly parser, so the xml document you are going to parse did not loaded completely to the memory ,SAX parser garantee that the document is parsed step by step ,only one element at a time
is treated .and so on till there is no more elements in the documnet,and this
technique is so valuable if you are comunicating with some server configuration xml files ,and you need urgent event driven actions,not to drop all the document into your memory and begin parsing.
2-what Really DOM doing is that it forms what's called a Tree of Nodes to the whole parts of the xml documnet when it begin parsing , so you will add this tree to your memory and them DOM begins his work .
so that's it

"Nothing is harder on your aurels than resting on them."<br />SCJP 1.4 89%,,SCJA 80%,SCWCD1.4 81%
Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502

SAX and DOM were both designed to allow programmers to access their information in XML without having to write a parser.

DOM Parser - use this when XML file size is small. Because of, it loads full XML in Tree Structure.

Advatage: You can iterate in both ways(back and forth). But SAX is event based model and iteration happens only in one way(forward).

Disadvatage: MEMORY CONSUMPTION IS MORE. In case of SAX it is less.

SAX parser- use this when XML size is huge.

Please have a look at this URL which gives in more detail about when to use SAX? and when to use DOM?


Prabhu Venkatachalam<br />SCJP 1.4,SCWCD 1.4<br />
I agree. Here's the link:
subject: differences between DOM and SAX parser?
jQuery in Action, 3rd edition