Archive for the 'Java And XML' Category

What Are The Differences Between SAX and DOM Parsers?

Kushal Paudyal January 21st, 2010

For the newbies, SAX stands for Simple API for XML and DOM stands for Document Object Model.
Both of these are APIs to parse XML documents. There is no direct competition between DOM and SAX
as both of them have there own strengths and weaknesses.

The following are some fundamental differnces between a SAX and DOM model of parsing.

SAX:

1. Parses the document on node by node basis.
2. Does not store the XML in memory.
3. We can not insert or delete a node.
4. This model uses top to bottom traversing.
5. This model does not preserve comments.
6. It runs little faster than DOM

DOM

1. Stores the entire XML document into memory before processing
2. Occupies more memory
3. We can insert or delete nodes
4. This model can traverse in any direction.
5. This model preserves comments.
6. It runs slower than SAX model

So, when to choose what model to use?

Here is what you can do.

If you just need to read a node, but do not require to insert/delte node, then use SAX.
If you require node manipulation(insert/delete) nodes, use DOM.

There are various parsers in Java that can be used. The following is a list of few java parsers.

  • Apache Parser [Xerces]
  • Oracle XML Parser
  • Sun XML Parser

All of these parsers provide SAX and DOM parsing mechanisms.

Related Tutorials




Sanjaal.com is owned and maintained by Sanjaal Corps, Nepal. The company offers Webhosting and Domain Registration Services, IT Solutions and Business Analysis. Sanjaal.com website features H1B Visa Information, Entertainment Portal, Link Directory Service, Free Articles, Free Open Source Tutorials on Java and J2EE Platform, Digital Photography, High Resolution Picture Gallery and Free Reliable Image Hosting Services. Future plan includes Open Source Software Development Portal, Technical Solutions and Customizable Movie and Music Arena. We would be introducing data backup, data recovery, data hosting and voip solutions. Stay free from phishing – our website does not ask for your credit card and banking information. Happy Surfing!

Blog Widget by LinkWithin

Originally posted 2009-02-11 16:42:17.

  • Share/Bookmark

Next »


Your Ad Here