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. |
Filed under: XML |
Nice and clear points gien. The concept is very clear.
Very Nice help ๐
great work ๐
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.
yes i got the points,,, thank you
Really good.
Thanks
this is ok
The conscept is very clear from the comparison itself…
Thanks
Really so nice difference.
Definitely great help for the beginers ….nicely written
good difference for understanding
Nice Differences..This is clear all my concept over the two parsers and also clear when to use one. Thanks a ton
Complete difference in very simple words. Thanks a lot dear !!!!
Very fine and simple difference, Thank u lot
Excellent explanation
Clear Explanation Thank you.
Understandable points.. thanku ๐
Thanx for giving information….
I got more help to my internal Xmzz….
ITS Ultimate site for Java and etc…..and Gud explanation
clear basic concept ๐
It is simple & sweet and upto the point
Thanks
Agree to all the praising comments
Great explaination. Thanks
http://www.google.com
Good Explanation,
Many Thanks ,Srikanth
Extraordinary work . keep posting such messages.simply great. Thanx lot sharat
its nice ..thanx for help…very clear difference.
thanks for giving clear information about dom & sax
[…] post info By Nagaraju Categories: Uncategorized Tags: dom, java, java interview questions, sax What are the differences between SAX and DOMย parser. […]
Short and sweet!!
its verygood answer
thanks a lot . it was a very good explanation
Crystal clear. good work
thanx…..the data provided is absolutely apt and understandable….good work
Excellent, expressed in a nut shell, thanks.
thanks:)
Very clear and straight forward……can be understand easily
Short and to the point.
Excellent…!! Thanks.
nice work . i need one more diff
which is best for two ( xml to java and java to xml ) either DOM or SAX.
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
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
Shemale posts are the best stress relief ever
I would like to read more stuff like this one
Good One…
tell me in which cases dom parser is advantageous than SAX
it sounds good…will be far better on further explanation….
It is a nice difference and explanation.
Very good, I needed this topic!
tks vy much!
really useful to all
wow great and info and good table comparison. Helps me better understands sax and dom. thanks a lot.
thankz lot