On 20 June 2012 13:08, Natarajan V <rajanvn at gmail.com> wrote:
On Wed, Jun 20, 2012 at 12:33 PM, Yogesh Girikumar
<yogeshg1987 at gmail.com> wrote:
Which is better to process streaming XML? (e.g. RSS) ?SAX or DOM? Why?Is your XML of unlimited size and keeps streaming in? Or is it a tiny
XML such as those RSS in news websites?
If it is continous and non-stop/ huge (of the order of 1 Mb), shy away from
DOM.
Yes, DOM reads the entire XML, converts it into objects, and is very
often implemented using a nested hash-map. It is quite heavy on
memory. BUT, it is quite usefull in terms speed of development and the
ability to enrich (edit) the XML. SAX on the otherhand is read only.
DOM and SAX are not the only options. There is a StAX parser as well.
Also note, now a days, there are tools, at least in the Java & .NET
world, where you supply a XML Schema, and the tool would create a
corresponding object representation (Similar to a Struct in C). You
can then import the generated code into your application and use a
list [array] of the generated objects. It can read as well as create
the XML. There won't be any code in your application to read the XMLs.
These would be externalized into those XML libraries. Eg. JAXB.