A Brief Description of XML SAX and DOM

by Steven J. Owens (unless otherwise attributed)

A short description of what XML SAX and DOM are about, for less technical readers (and no, there's nothing kinky about it :-).

SAX is essentially a collection of helpful functions and such for searching through the XML text document.

For example, you could hand-code a method to:

1) search for "

2) check to see if there's a "/>" before a ">",

3) if 2 is false, search for "",

4) return everything from the start to either the "/>" or the " as the next tag

Or you could stick that code in the SAX parser and then call a method to get the next tag. Put together a coherent, systematic set of such useful things, and add in niftiness like hooks to kick off events as you work through the stream of text. And that's (a very simplified description of) SAX.

So SAX is a tool to let you interact with the stream of XML text in a structured way, and ignore the details of searching the string.

DOM (short for Document Object Model), on the other hand, is a tool for interacting with a structure of data. You use a SAX type parser to convert the stream of XML text and stuff it into a DOM, which keeps the data and the structure. Then you use convenience methods on the DOM to interact with that structure and get selective bits of data out of it.

You could roll your own DOM for a particular task, but it ends up being a custom job that mostly only works for a specific task, and there's all sorts of cleverness you may not know about to speed it up and make it more reliable and so forth. As it turns out, the World Wide Web Consortium defined a generic, standard way of interacting with a DOM and various people have implemented various generic DOMs.

So a DOM is a tool to hold a generic structure of data and let you interact with it.


See original (unformatted) article

Feedback

Verification Image:
Subject:
Your Email Address:
Confirm Address:
Please Post:
Copyright: By checking the "Please Post" checkbox you agree to having your feedback posted on notablog if the administrator decides it is appropriate content, and grant compilation copyright rights to the administrator.
Message Content: