Sunday, February 12, 2012

What are the differences between SAX and DOM parser xml parsing webservices



What are the differences between SAX and DOM parser


SAXDOM
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 nodeStores the entire XML document into memory before processing
Doesn’t store the XML in memoryOccupies more memory
We cant insert or delete a nodeWe can insert or delete nodes
Top to bottom traversingTraverse in any direction.
SAX is an event based parserDOM is a tree model parser
SAX is a Simple API for XMLDocument 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 commentspreserves comments
SAX generally runs a little faster than DOMSAX 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.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...