Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Parsers

 
Dharmesh Gangani
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am very much confused about the Parsers. Which parsing method (DOM or SAX) is best suited and recommended..

Please help..
 
Sas Jacobs
Author
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

DOM and SAX provide two different approach to XML parsing.

In DOM parsers, the entire XML document is parsed into a tree and developers can use scripting to access parts of that tree. The point here is that the DOM parser needs to process the entire XML document. The document is retained in memory and can be accessed more than once.

SAX parsing is event-based and the XML document isn't retained in memory by the parser. As each event fires, the SAX parser can respond with an appropriate event handler created by the developer. It's argued that this is a much more efficient processing model.

The parser choice is determined by the XML application type. Simplistically, if a large XML document contains only a small amount of data to which an application needs to respond, it would make sense to use a SAX parser. If the application needs to repeatedly access content from the XML document, a DOM parser is appropriate.

Cheers

Sas Jacobs
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about Stax ? Is it getting popular?
 
Kj Reddy
Ranch Hand
Posts: 1704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to take a decision on which parser to be used?
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by KJ Reddy:
How to take a decision on which parser to be used?


Sas has already talked about SAX and DOM. Stax is a pull based parser when you tell the parser to get the next XML token (element, string etc). It is easier to code using Stax. It can read larger XML documents and also be used to create XML document unlike SAX.Hope this helps.
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wish to add that XSLT makes use of DOM parsing as it may need to access elements randomly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic