Oracle8i Application Developer's Guide - XML Release 3 (8.1.7) Part Number A86030-01 |
|
Using XML Parser for Java, 4 of 22
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>
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
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.
Here are some 'rules of thumb' for using DOM and SAX APIs:
Use the SAX interface when data comes in a streaming manner (using some I/Pstream).
|
Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
|