I know that even SAX is preffered to when reading Long XML docs. Others that SAX is also prefered when data is not in XML format Can anybody tell me abt no-XML format.
Use SAX parser when - Input document is too big for available memory. - When only a part of the document is to be read and we create the data structures of our own. - If you use SAX, you are using much less memory and performing much less dynamic memory allocation.
Use DOM when - Your application has to access various parts of the document and using your own structure is just as complicated as the DOM tree. - Your application has to change the tree very frequently and data has to be stored for a significant amount of time.
basically SAX is strictly read-only so if you need to modify the XML document in any form (or create one from scratch) you MUST use DOM.
Then there's the potential problem of repeated access to elements which is impossible in SAX, so if you need to do things which require you to process something more than once you will again need DOM (or use your own caching mechanism on top of SAX).
Then there's personal preference. I just like DOM better, to me it's more intuitive and easier to use than is SAX.
basically SAX is strictly read-only so if you need to modify the XML document in any form (or create one from scratch) you MUST use DOM.
I can't agree with that. You can read using SAX, perform logical operations and write a new document using the data in SAX events. Naturally you are limited in the kinds of logic you can perform due to the streaming order of the SAX events. For example, modifying the attributes in selected XML elements is easily done in a startElement method. There are many other ways to create an XML document besides building a DOM in memory. Bill