Oracle8i Application Developer's Guide - XML
Release 3 (8.1.7)

Part Number A86030-01

Library

Solution Area

Contents

Index

Go to previous page Go to beginning of chapter Go to next page

Using XML Parser for Java, 4 of 22


DOM and SAX APIs

XML APIs generally fall into the following two categories:

See Figure 17-3. Consider the following simple XML document:

<?xml version="1.0"?>
  <EMPLIST>
    <EMP>
     <ENAME>MARY</ENAME>
    </EMP>
    <EMP>
     <ENAME>SCOTT</ENAME>
    </EMP>
  </EMPLIST>

DOM: Tree-Based API

A tree-based API (such as Document Object Model, DOM) builds an in-memory tree representation of the XML document. It provides classes and methods for an application to navigate and process the tree.

In general, the DOM interface is most useful for structural manipulations of the XML tree, such as reordering elements, adding or deleting elements and attributes, renaming elements, and so on. For example, for the XML document above, the DOM creates an in-memory tree structure as shown in

SAX: Event -Based API

An event-based API (such as SAX) uses callbacks to report parsing events to the application. The application deals with these events through customized event handlers. Events include the start and end of elements and characters.

Unlike tree-based APIs, event-based APIs usually do not build in-memory tree representations of the XML documents. Therefore, in general, SAX is useful for applications that do not need to manipulate the XML tree, such as search operations, among others.

The above XML document becomes a series of linear events as shown in Figure 17-3.

Figure 17-3 Comparing DOM (Tree-Based) and SAX (Event-Based) APIs


[

Guidelines for Using DOM and SAX APIs

Here are some 'rules of thumb' for using DOM and SAX APIs:

DOM:

SAX:

Use the SAX interface when data comes in a streaming manner (using some I/Pstream).


Go to previous page Go to beginning of chapter Go to next page
Oracle
Copyright © 1996-2000, Oracle Corporation.

All Rights Reserved.

Library

Solution Area

Contents

Index