Solved

SAX vs. DOM

Posted on 2000-05-02
3
1,412 Views
Last Modified: 2008-02-26
Can anyone discuss, in detail, the advantages or disadvantages of using SAX to parse an XML file rather than DOM?  Are there any particular qualities that a file containing XML should have which would make it more suitable for one or the other???
0
Comment
Question by:callapm
3 Comments
 

Expert Comment

by:deanejoyce
Comment Utility
Basically sax is a serial API and dom needs the whole document model in order to process stuff.....

if you have a large database or distributed datbases containing lots of info, use sax.....it's way quicker.....

if your documents or database are relatively small use dom....

so in a b2b situation I nearly always go for sax unless you are dealing with a small vendor....

I hear the new apache/perl validating parser is pretty good for DOM, so perhaps you should check it out.....

deane

0
 
LVL 44

Expert Comment

by:bruintje
Comment Utility
Hi callapm,

That's a long discussion, for more perspective

http://www.xml.com/pub/Guide/SAX_vs._DOM

or for SAX
http://www.xml.com/pub/Guide/SAX
or DOM
http://www.xml.com/pub/Guide/DOM

HTH:O)Bruintje
0
 
LVL 27

Accepted Solution

by:
BigRat earned 50 total points
Comment Utility
The difference lies in processing.

   If you want to simply extract data from an XML document then using SAX is easiest. The method involves sequentially reading the file and when a certain "token" (such as element start or end (<element> and </element>) occurs a particular call back procedure which you supply is called. To boldly go (I couldn't resist that) through a file looking at all <fred>s is particularly easy. It gets more complex when you want to look at fred included in jim. You yourself must provide programming logic to sieve out the events. For example you must set a flag on jim's start, process a fred only when the flag is set, and reset the flag on jim end.
   Note also with SAX you cannot modify the file, and that is a big weakness.

  As Deane said, the DOM parser reads the entire file into memory and constructs a tree. You can walk this tree as you wish. You can delete and create new nodes in the tree, which can correspond to element data or attributes. And of course you can modify all the elements, their attributes and the order of the elements. The MS XML ActiveX object is a DOM parser.

   You should also remember than an XSL stylesheet transformer is effectively a DOM parser.

   A good explaination of both DOM and SAX can be found in Sams Teach Yourself XML in 21 Days (ISBN 1-57521-396-6) (which I did not write but heartily recommend).
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now