Ok, I'm having some troubles grasping this whole SAX thing.
You are not the first one : )
> What's the benefits to using SAX?
SAX has the major benefit of low memory consumption as the entire document
does not need to be loaded into memory at once. Additionally you do not have
to create objects for all of the nodes (as you would in DOM)-- the speed
difference is therefore also critical.
The downside to SAX is that you must maitain the state (e.g. you have to
keep track of where the parser is in the document heirarchally) This is
pretty easy to do with a TStack-- you can push elements on the stack in the
startElement and pop them in endElement.
So when should you use SAX and when should you use DOM? That is a big
question. Sometimes if you are passing a document all over the place and it
is small-- DOM is better. It saves parsing over and over. If you just need
to get a few values out of a document SAX is King. In Beginning XML (Wrox)
it is described as follows:
Let's say you wanted to find the Fabulous Lost Treasure of the Xenics in a
labyrinth-- you don't need to create a map of the whole maze do you? No you
just need to keep going till you find it. Once you find it you can leave.
SAX is the way.
However if you do need to create a whole map-- DOM is the way.
> How does MSXML come into play with SAX. If I use
> MSXML now stand alone, what's the difference in using it with SAX.
When people say MSXML they are often referring to the DOM implementation or
the XSLT implementation. MSXML 3+ has a decent SAX implementation as well.
You can use that without using anything else but you are tied to a platform
(Windows). If you do use SAX I would suggest that you use the SAX for Pascal
implmentation at http://xml.defined.net/SAX it was co-developed by people on
this list. Using that (and Keith's MSXML wrapper) you can use MSXML no
problem. There are several other vendors for SAX parsing available now as
well.
Best Regards,
--
Jeff Rafter
Defined Systems
home
Last updated 31.12.2001