This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
That is exactly backwards from the usual advice (which is not all that useful anyway.) People decide between SAX and DOM by looking at what the program has to do with the document once it has been read.
Originally posted by Mortin kim: can any one tell me what are the differences between SAX and DOM..? Where Excetly DOM Fits and SAX fits.?
You may use DOM when you are going to build xml from elements or you need to traverse between xml nodes backward and forward to decide on your next action, edit the document... Dom will load your xml into memory so it is memory consumer, from the other hand it gives you the most possible flexibility with an almost easy to use API.
SAX, on the other hand, will pars the document and let you catch some events based on what kind of element parser found during its parse operation. It is forward only, fast and it is not that kind of memory consumer which DOM is. It can not help you with XML authoring and client (your code which use the parser) will bound to parser to complete its operation.
FYI: Stax, let you have all good thing that sax has, also it allows you to write xml, it is not a pull parse so your parser client will not lock for the parser until it complete the document.
You should select your Parser based on several condition like: -maximum and minimum size of document which need to be parsed -validation requirement -one way parsing or traversing in the document -...
I can say it simply. DOM: I am interested in hierarchy of elements. That means I want to manipulate easily elements of different depth within a method. SAX: I want to use DOM, but I don't have enough memory and XML files are too big.
:shocked: That is exactly backwards from the usual advice (which is not all that useful anyway.) People decide between SAX and DOM by looking at what the program has to do with the document once it has been read.
Sorry. My mistake. It's just reverse.
Mortin, XML has some character which has meaning like <, >, " etc. Events are raised whenever such character occurs and interpreted accordingly.
I would like to correct myself. Use Stax whereever possible.I can't be used everywhere.Stax has the disadvantages that it is not easier to navigate like DOM. No ability to create,update, delete elements