Difference between SAX and DOM Parsers

Author posted by Jitendra on Posted on under category Categories JAVA and tagged as Tags with Leave a comment on Difference between SAX and DOM Parsers

What is the difference between SAX And DOM Parsers

In Previous articles we have discussed about JAXP in detail.

To summarize all, lets discuss difference between both approach.

SAX Parser:

  1. Event based model.
  2. Serial access (flow of events).
  3. Low memory usage (only events are generated).
  4. To process parts of the document (catching relevant events).
  5. To process the document only once.
  6. Backward navigation is not possible as it sequentially processes the document.
  7. Objects are to be created.

DOM Parser:

  1. (Object based)Tree data structure.
  2. Random access (in-memory data structure).
  3. High memory usage (the document is loaded into memory).
  4. To edit the document (processing the in-memory data structure).
  5. To process multiple times (document loaded in memory).
  6. Ease of navigation.
  7. Stored as objects.

For simpler applications, that complexity may well be unnecessary. For faster development and simpler applications, one of the object-oriented XML-programming standards, such as JDOM ( http://www.jdom.org) and DOM4J ( http://dom4j.org/), might make more sense.

Related posts