Monday, April 30, 2012

How to : choose between DOM, SAX or XMLStreamWriter

What is XML : I call it a "language for Internet", It help applications to communicate  seamlessly. At the same time it's in human readable format too. Any XML file typically contains 'Elements' and 'Attributes', which are also called XML 'Node'. 
(Element, CData, Comment, Attribute, Entity, Text are few examples of Node Type).
There are number of API(s) available to work with XML, and each has its positive and negative aspects.


W3C DOM : 
good for - random read and  write with XML nodes.
not suitable for - larger memory footprint, performance.
SAX :
good for : faster read access, it's lightweight.
not suitable for - writing/creating XML nodes.
XMLStreamWriter :
good for - streaming out XML while building it, useful in web services handling larger files.
not suitable for - random read or write, It's sequential, one-way, cursor like implementation. 


All what you need is to choose your API closest to your need. XMLStreamWriter is a good for all purpose. Most effective for mobile devices.

Thank YOU

No comments:

Post a Comment