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
Solved

SAX vs. DOM

Posted on 2000-05-02
3
1,418 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
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do i send an api key in a request header 3 83
c# code 19 72
How do I bind the results to a grid 3 42
MS Access XML Export Query Setup Multiple Tag Values 15 40
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
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.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

789 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