Meaningless Drivel is fun!*
The moose likes XML and Related Technologies and the fly likes DOM or SAX confusing 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 "DOM or SAX confusing" Watch "DOM or SAX confusing" New topic
Author

DOM or SAX confusing

Pardha
Greenhorn

Joined: May 13, 2001
Posts: 15
hi
sitll Iam confused whether to use DOM or SAX
how to decide which one to be opted and what
criteria shall I have to opt.
Thanking u
Saradhi


Intelligent Hard work never goes waste
Hemant KS Sengar
Greenhorn

Joined: Apr 26, 2001
Posts: 5
Hi!
DOM is best suited for :
1)When structurally modifying an XML document
2)When sharing the document in memory with other Applications
3)for applications that operate on the document as a whole
SAX:
1)Dealing with large document that does not fit in memory
2)extracting contents of a specific element
Hope it will help!
Hemant
Originally posted by saradhi74:
hi
sitll Iam confused whether to use DOM or SAX
how to decide which one to be opted and what
criteria shall I have to opt.
Thanking u
Saradhi

Pardha
Greenhorn

Joined: May 13, 2001
Posts: 15
Hi thnk u
I got it now and also I woul like to share the some more info which I have collected.
SAX OR DOM
SAX :-
SAX is a stream-based parsing process. You can easily configure a SAX parse to grab certain tags and/or their contents, and ignore others. This makes it quick and effective for extracting specific information from potentially large XML sources.
Another important different is that SAX is read-only while DOM is read-write. This means SAX doesnot have any facility using which one can change the content of the XML document being parsed. On the otherhand, DOM provides mutator methods to get/set XML data and the changes done during parsing are durable.
DOM :-
DOM is a document-based parsing process. A DOM parser reads a whole XML source into a large, complex internal structure and provides lots of operations to extract, insert and modify the loaded data. DOM is good for when you need to load and transform whole documents, or create new XML documents in memory ready for such a peocess.

Perhaps this is the one of the most compelling reason to consider DOM-parsing despite of its performance issues. Ofcourse one can always implement a hybrid-SAX that allows manipulating the XML content. It is not impossible, but may be redundant since DOM is available out there which can do the exact same thing!

-----
Which approach to use also depends on the ultimate use for the data. If you are parsing the XML in order to build some application-specific data structure from it, then using DOM can result in even larger memory requirements, as you duplicate all the information in the DOM while building it.
Don't forget though, that there is a difference between the DOM and a DOM. You can build your own lighter-weight Document Object Model, using SAX or any other simple parsing system. JDOM is an example of this; it's a full document model which is much easier to traverse in Java than using the official DOM interface.
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
"saradhi74",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.
Thanks.
You have already been warned about the user name you have chosen. This name will soon be turned off, so please choose another name immediately.

Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Murali Mohan
Ranch Hand

Joined: Jun 14, 2001
Posts: 47
1)SAX is faster than DOM.
2)SAX is good for large documents because it takes comparitively less memory than Dom.
3)SAX takes less time to read a document where as Dom takes more time.
4)With SAX we can access data but we can't modify data.
5)We can stop the SAX parsing when ever and where ever you want.
6)SAX is sequential parsing but with DOM we can move to back also.
7)To parse machine generated code SAX is better.To parse human readable documents DOM is useful.
[This message has been edited by Murali Mohan (edited June 15, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DOM or SAX confusing
 
Similar Threads
How do i obtain unique value thru this code
how to validate xml using local xsd
What is the difference between SAX and DOM ?.
SAX Vs DOM
Class Path