[Ilugc] [ILugC] XML processing

  • From: rajanvn@xxxxxxxxx (Natarajan V)
  • Date: Wed, 20 Jun 2012 13:08:14 +0530

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.

I read up a bit on SAX and here's what the Wikipedia article says;
"Where the DOM operates on the document as a whole, SAX parsers
operate on each piece of the XML document sequentially."

Does it mean that DOM reads the whole document before processing it?

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.

DOM is object oriented
SAX works on Tag events (read only)
StAX is a "pull" parser (read only)

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.


with regards,
Natarajan

Other related posts: