Share with you (Internet Application)

Wednesday, April 04, 2007

W11-XML DOM and SAX

Document Object Model (DOM) is a platform- and language-independent standard object model for representing HTML or XML and related formats. Strictly speaking, one should refer to "the DOM", but in practice, the "the" article is usually dropped.
Because DOM supports navigation in any direction (e.g., parent and previous sibling) and allows for arbitrary modifications, an implementation must at least buffer the document that has been read so far (or some parsed form of it). Hence DOM is likely to be best suited for applications where the document must be accessed repeatedly or out of sequence order. If the application is strictly sequential and one-pass, the SAX model is likely to be faster and use less memory.


The Simple API for XML (SAX) is a serial access parser API for XML. SAX provides a mechanism for reading data from an XML document. It is a popular alternative to the Document Object Model (DOM).
The W3C DOM specifications are divided into levels, each of which contains required and optional modules. To claim to support a level, an application must implement all the requirements of the claimed level and the levels below it. An application may also support vendor-specific extensions which don't conflict with the W3C standards. As of 2005, Level 1, Level 2, and some modules of Level 3 are W3C Recommendations which means they have reached their final form.
Level 0
The application supports an intermediate DOM, which existed before the creation of DOM Level 1. Examples include the DHTML Object Model or the Netscape intermediate DOM. Level 0 is not a formal specification published by the W3C but rather a shorthand that refers to what existed before the standardization process.
Level 1
Navigation of DOM (HTML and XML) document (tree structure) and content manipulation (includes adding elements). HTML-specific elements are included as well.
Level 2
XML namespace support, filtered views and events.
Level 3
Consists of 6 different specifications:
DOM Level 3 Core;
DOM Level 3 Load and Save;
DOM Level 3 XPath;
DOM Level 3 Views and Formatting;
DOM Level 3 Requirements; and
DOM Level 3 Validation, which further enhances the DOM
-------------------------------------------------------------------------------
A parser which implements SAX (ie, a SAX Parser) functions as a stream parser, with an event-driven API. The user defines a number of callback methods that will be called when events occur during parsing. The SAX events include:
XML Text nodes
XML Element nodes
XML Processing Instructions
XML Comments
Events are fired when each of these XML features are encountered, and again when the end of them is encountered. XML attributes are provided as part of the data passed to element events.
SAX parsing is unidirectional; previously parsed data cannot be re-read without starting the parsing operation again.
----------------------------------------------------------------------------------