Untitled Document
Untitled Document
The following APIs provide a Java application with access to a parsed XML document:
DOM API, which parses XML documents and builds a tree representation of the
documents in memory. Use either a DOMParser object to parse with DOM or the
XMLDOMImplementation interface factory methods to create a pluggable, scalable DOM.
SAX API, which processes an XML document as a stream of events, which
means that a program cannot access random locations in a document. Use a SAXParser
object to parse with SAX.
JAXP, which is a Java-specific API that supports DOM, SAX, and XSL. Use a
DocumentBuilder or SAXParser object to parse with JAXP.
The sample XML document in Example 4-1 helps illustrate the differences among DOM, SAX, and JAXP.
Example 4-1 Sample XML Document
<?xml version="1.0"?>
<EMPLIST>
<EMP>
<ENAME>MARY</ENAME>
</EMP>
<EMP>
<ENAME>SCOTT</ENAME>
</EMP>
</EMPLIST>
DOM API is easier to use than SAX because it provides a familiar tree structure
of objects.
Structural manipulations of the XML tree, such as re-ordering elements, adding to
and deleting elements and attributes, and renaming elements, can be performed.
Interactive applications can store the object model in memory, enabling users to
access and manipulate it.
DOM as a standard does not support XPath. However, most XPath
implementations use DOM. The Oracle XDK includes DOM API extensions to support
XPath.
A pluggable, scalable DOM can be created that considerably improves scalability
and efficiency.
DOM Creation
In Java XDK, there are three ways to create a DOM:
Parse a document using DOMParser. This has been the traditional XDK
approach.
Create a scalable DOM using XMLDOMImplementation factory methods.
Use an XMLDocument constructor. This is not a common solution in XDK.
Scalable DOM
With Oracle 11g Release 1 (11.1), XDK provides scalable, pluggable support for DOM. This relieves
problems of memory inefficiency, limited scalability, and lack of control over the DOM configuration.
For the scalable DOM, the configuration and creation are mainly supported using the
XMLDOMImplementation class.
These are important aspects of scalable DOM:
It is useful for search operations and other programs that do not need to
manipulate an XML tree.
It does not consume significant memory resources.
It is faster than DOM when retrieving XML documents from a database.
Figure 4-2 Comparing DOM (Tree-Based) and SAX (Event-Based) APIs
Description of "Figure 4-2 Comparing DOM (Tree-Based) and SAX (Event-Based) APIs"