aspose file tools*
The moose likes XML and Related Technologies and the fly likes Parsers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Parsers" Watch "Parsers" New topic
Author

Parsers

Dharmesh Gangani
Ranch Hand

Joined: Feb 20, 2004
Posts: 30
I am very much confused about the Parsers. Which parsing method (DOM or SAX) is best suited and recommended..

Please help..


-=-=-=-=-=-=-=-=-=-<br />Thanks & Regards,<br />Dharmesh G.
Sas Jacobs
Author
Ranch Hand

Joined: Jun 24, 2006
Posts: 46
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

Joined: Feb 27, 2002
Posts: 8919

What about Stax ? Is it getting popular?


Groovy
Kj Reddy
Ranch Hand

Joined: Sep 20, 2003
Posts: 1704
How to take a decision on which parser to be used?
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

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

Joined: Feb 27, 2002
Posts: 8919

I wish to add that XSLT makes use of DOM parsing as it may need to access elements randomly.
 
 
subject: Parsers