Key Difference of DOM and SAX
DOM stands for Document Object Model while SAX stands for Simple API for XML parsing. DOM parser load full XML file in memory and creates a tree representation of XML document, while SAX is an event based XML parser and doesn't load whole XML document into memory.
So SAX takes less memory while DOM take more memory.
Another Difference of DOM and SAX
SAX is sequential one . if you want to parse an element in n th line of xml, one need to traverse all the xml until n th line.
But DOM is not like that. using XPath techniques, you can parse any element directly.
Say if you have an xml document with some 2000 lines, and if you want to parse only 1980 line then, DOM parser directly fetch
it using XPath. for SAX paser it reads line by line sequential so its very slow but takes less memory.
So DOM is fast for parsing partial elements.
Ads By Google
© 2018 - JavaSpartans.com • All Rights Reserved