• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

SAX vs DOM

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can any one tell me what are the differences between SAX and DOM..?
Where Excetly DOM Fits and SAX fits.?
 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.?



In very brief, SAX is lowest level parser works on event based mechanism. DOM instead loads XML document into memory as a tree and then traverse node for information.

If XML is small then SAX is good else DOM.

Usually people don't use these low level parsers nowadays. You can look for JDOM, Castor, XMLBeans, JAXB etc.

Search forum or net for more information.

 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If XML is small then SAX is good else DOM.



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.

Bill
 
Mortin kim
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI rathi ji.,
what is event based machanisam..can you explain brifly..?
 
Author
Posts: 531
Mac OS X Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
-...

hope it helps.
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by William Brogden:

: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.

Bill



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.

 
Ranch Hand
Posts: 8953
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Move away from SAX and DOM , use StAX.
 
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Prad, what are the advantages you can get by using STAX? How do you supposed to replace that SAX/ DOM behavior by STAX?
 
Pradeep bhatt
Ranch Hand
Posts: 8953
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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


Here is a good article comparing the three approaches
http://www.oracle.com/technology/oramag/oracle/03-sep/o53devxml.html

http://java.sun.com/javaee/5/docs/tutorial/doc/bnbdw.html#bnbea
 
Dilshan Edirisuriya
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes Prad that links describes those issues. Thank you
 
Fire me boy! Cool, soothing, shameless self promotion:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic