• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

DOM or SAX confusing

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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.
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic