Archive

Posts Tagged ‘SAX’

SAX vs DOM Parser – Concept Revisited

Image

 

Both SAX and DOM Parser’s are used to parse the XML document. Both has advantages and disadvantages and can be used in our programming depending on the situation.

SAX: Is a stream-based processor. You only have a tiny part in memory at any time and you “sniff” the XML stream as it passes. It uses almost no memory, but you can’t do “DOM” stuff, like use xpath or traverse trees.

DOM: You load the whole thing into memory – it’s a massive memory hog. You can blow memory with even medium sized documents. But you can use xpath and traverse the tree etc.

 

SAX:

  • Parses node by node
  • Doesn’t store the XML in memory
  • We cant insert or delete a node
  • SAX is an event based parser
  • SAX is a Simple API for XML
  • doesn’t preserve comments
  • SAX generally runs a little faster than DOM

DOM:

  • Stores the entire XML document into memory before processing
  • Occupies more memory
  • We can insert or delete nodes
  • Traverse in any direction.
  • DOM is a tree model parser
  • Document Object Model (DOM) API
  • Preserves comments
  • 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.

Read More on SAX:

http://en.wikipedia.org/wiki/Simple_API_for_XML

Categories: Uncategorized Tags: , , ,
%d bloggers like this: