Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

What is DOM SAX

What is DOM SAX

What is DOM SAX

I've seen DOM SAX stuff mentioned before.

Pardon me if this isn't the right forum to post on, but could someone explain or direct me to somewhere where I could learn about this stuff?

much thanks,

RE: What is DOM SAX

DOM is "Document Object Model". SAX is "Simple API for XML".

I'm learning from a book and from working on a project that uses XML.

Thomas D. Greer
Providing PostScript & PDF
Training, Development & Consulting

RE: What is DOM SAX

Here is a simple explanation between the two that I always use by comparing DOM and SAX to women and men.  Hate it if you want, but its totally true.

So if we take the stereotype of communication, DOM is like a woman and SAX is like a man.

If an instructor was giving a two minute speech, the woman (DOM) would record the whole speech into memory and be able to tell you everything you want to know about the speech.  Luckily, the speech was only two minutes, so it did not take much time to remember it.  She can tell you the beginning of the speech, the end, or any part of it.  The guy (SAX) can only react to the speech, because it goes in one ear and out the other.  If you tell him to remember something after he heard the speech, it ain't gonna happen.  The guy (SAX) needs to be aware of what he is listening for and then he can tell you what he hears as he hears it.  This can be bad if you want to move back and forth between the speech and review parts that have already been communicated.

Now lets assume the teacher gives a two hour speech.  The woman (DOM) is going to have a hell of a time remember everything about the speech.  If she attempts to do this, she is going to have memory overload and work really slow to remember the whole speech.  Where the guy (SAX) works faster because he only listens to the parts of the speech that he wants to.  He doesn't have to remember the whole speech.  That's the difference.

DOM pulls the whole XML document into memory.  This allows the parser to move forwards, as well as backwards.  This allows you to pass the DOM object around and retrieve pieces of that original document.  But as the document gets bigger, so does the DOM.  And DOM represents every node as its own little mini object, so the more nodes you have, the bigger the document.

SAX reads the document like a stream.  It uses event handlers to tell the program that it has met a condition.  So if you are looking for a specific element, you can put code in the startElement that says when you read a document that hits the tag "html" (for instance), let me know.  SAX can read a document faster because it does not load the document into memory.  Unfortunately, SAX cannot move backwards because it reads from start to finish (one ear out the other).  The other problem with SAX is that if you hit a piece of content you want, and you don't want to do anymore, you have to read the whole document.  The only way to stop SAX is to throw an exception.

This is where StAX comes in.  It is a more advanced version of SAX that lets you define when the events get triggered.

Most programming will utilize SAX, DOM is just to memory intensive.  You can make it as fast as you want, but you still suck up memory.  Just like XSLT translations.  They can get faster and faster, but they suck up memory like a hog.

Hope this helps.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close