Solved

SAX vs. DOM

Posted on 2000-05-02
3
1,421 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Expert Comment

by:deanejoyce
ID: 2770274
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
ID: 2770787
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
ID: 2770839
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

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

632 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