You are on page 1of 16

7-Oct-14

DOM
SAX and DOM
SAX and DOM are standards for XML parsers--
program APIs to read and interpret XML files
DOM is a W3C standard
SAX is an ad-hoc (but very popular) standard
There are various implementations available
Java implementations are provided in JAXP (Java API
for XML Processing)
JAXP is included as a package in Java 1.4
JAXP is available separately for Java 1.3
Unlike many XML technologies, SAX and DOM are
relatively easy
Difference between SAX and DOM
DOM reads the entire XML document into memory and
stores it as a tree data structure
SAX reads the XML document and sends an event for each
element that it encounters
Consequences:
DOM provides random access into the XML document
SAX provides only sequential access to the XML document
DOM is slow and requires huge amounts of memory, so it cannot
be used for large XML documents
SAX is fast and requires very little memory, so it can be used for
huge documents (or large numbers of documents)
This makes SAX much more popular for web sites
Some DOM implementations have methods for changing the XML
document in memory; SAX implementations do not
DOM
The XML DOM is the Document Object Model for
XML
The XML DOM is platform- and language-independent
The XML DOM defines a standard set of objects for
XML
The XML DOM defines a standard way to access XML
documents
The XML DOM defines a standard way to manipulate
XML documents
The XML DOM is a W3C standard

The DOM views XML documents as a tree-structure.
All elements; their containing text and their attributes,
can be accessed through the DOM tree.
Their contents can be modified or deleted, and new
elements can be created.
The elements, their text, and their attributes are all
known as nodes.

According to the DOM, everything in an XML
document is a node. The DOM says that:
The entire document is a document node
Every XML tag is an element node
The texts contained in the XML elements are text nodes
Every XML attribute is an attribute node
Comments are comment nodes

DOM Node Hierarchy Example

Look at the following XML file: books.xml

The following image illustrates a fragment of the DOM
node tree from the XML document above:

DOM levels: level 0


DOM Level 0 is a mix of Netscape Navigator 3.0 and
MS Internet Explorer 3.0 document functionalities.
DOM levels: DOM 1

It contains functionality for document navigation and
manipulation.


i.e.: functions for creating, deleting and changing elements
and their attributes.
DOM level 1 limitations
A structure model for the internal subset and the
external subset.
Validation against a schema.
Control for rendering documents via style sheets.
Access control.
Thread-safety.
Events
DOM levels: DOM 2
A style sheet object model and defines functionality for
manipulating the style information attached to a
document.
Enables of the traversal on the document.
Defines an event model.
Provides support for XML namespaces
DOM levels: DOM 3
Document loading and saving as well as content models
(such as DTDs and schemas) with document validation
support.

Document views and formatting, key events and event
groups
The End