83. What are the differences between SAX and DOM parser.

SAX DOM
Both SAX and DOM are used to parse the XML document. Both has advantages and disadvantages and can be used in our programming depending on the situation.
Parses node by node Stores the entire XML document into memory before processing
Doesn’t store the XML in memory Occupies more memory
We cant insert or delete a node We can insert or delete nodes
Top to bottom traversing Traverse in any direction.
SAX is an event based parser DOM is a tree model parser
SAX is a Simple API for XML Document Object Model (DOM) API
import javax.xml.parsers.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
 
doesn’t preserve comments preserves comments
SAX generally runs a little faster than DOM SAX generally runs a little faster than DOM
If we need to find a node and doesn’t need to insert or delete we can go with SAX itself otherwise DOM provided we have more memory.
Advertisements

49 Responses

  1. Nice and clear points gien. The concept is very clear.

  2. Very Nice help 🙂

    great work 🙂

  3. One more thing……..

    SAX: in a class or application module where you need to read the XML file and then do some processing, SAX adds the disadvantage of completing the work then and there only. next in another part, but same application scope, you need to read and know the xml, do everything again.
    DOM: since the xml is in the memory in an object form, you can utilise here and then there, means in some next step, provided u have memory and you keep the Objectified XML in memory, so no need to do the DOM code again.

  4. yes i got the points,,, thank you

  5. Really good.
    Thanks

  6. this is ok

  7. The conscept is very clear from the comparison itself…
    Thanks

  8. Really so nice difference.

  9. Definitely great help for the beginers ….nicely written

  10. good difference for understanding

  11. Nice Differences..This is clear all my concept over the two parsers and also clear when to use one. Thanks a ton

  12. Complete difference in very simple words. Thanks a lot dear !!!!

  13. Very fine and simple difference, Thank u lot

  14. Excellent explanation

  15. Clear Explanation Thank you.

  16. Understandable points.. thanku 🙂

  17. Thanx for giving information….

    I got more help to my internal Xmzz….

  18. ITS Ultimate site for Java and etc…..and Gud explanation

  19. clear basic concept 🙂

  20. It is simple & sweet and upto the point
    Thanks

  21. Agree to all the praising comments

  22. Great explaination. Thanks
    http://www.google.com

  23. Good Explanation,

    Many Thanks ,Srikanth

  24. Extraordinary work . keep posting such messages.simply great. Thanx lot sharat

  25. its nice ..thanx for help…very clear difference.

  26. thanks for giving clear information about dom & sax

  27. […] post info By Nagaraju Categories: Uncategorized Tags: dom, java, java interview questions, sax What are the differences between SAX and DOM parser. […]

  28. Short and sweet!!

  29. its verygood answer

  30. thanks a lot . it was a very good explanation

  31. Crystal clear. good work

  32. thanx…..the data provided is absolutely apt and understandable….good work

  33. Excellent, expressed in a nut shell, thanks.

  34. thanks:)

  35. Very clear and straight forward……can be understand easily

  36. Short and to the point.
    Excellent…!! Thanks.

  37. nice work . i need one more diff

    which is best for two ( xml to java and java to xml ) either DOM or SAX.

  38. sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss

  39. You may want to look at vtd-xml as the state of the art in XML processing, consuming far less memory than DOM

    vtd-xml

  40. Shemale posts are the best stress relief ever

  41. I would like to read more stuff like this one

  42. tell me in which cases dom parser is advantageous than SAX

  43. it sounds good…will be far better on further explanation….

  44. It is a nice difference and explanation.

  45. Very good, I needed this topic!

    tks vy much!

  46. really useful to all

  47. wow great and info and good table comparison. Helps me better understands sax and dom. thanks a lot.

  48. thankz lot

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: