0% found this document useful (0 votes)
171 views4 pages

Untitled Document

The document discusses several XML parsing APIs in Java: - DOM builds an in-memory tree of the XML document that allows navigation and manipulation of the tree. Scalable DOM improves memory efficiency. - SAX is event-based and does not build a tree, instead reporting events as it parses the XML linearly. - JAXP enables plugging in different DOM or SAX parser implementations but runs slower than vendor APIs.

Uploaded by

Bharathi N Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
171 views4 pages

Untitled Document

The document discusses several XML parsing APIs in Java: - DOM builds an in-memory tree of the XML document that allows navigation and manipulation of the tree. Scalable DOM improves memory efficiency. - SAX is event-based and does not build a tree, instead reporting events as it parses the XML linearly. - JAXP enables plugging in different DOM or SAX parser implementations but runs slower than vendor APIs.

Uploaded by

Bharathi N Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Document Object Model (DOM).

DOM is an in-memory tree representation of


the structure of an XML document.
Simple API for XML (SAX). SAX is a standard for event-based XML parsing.
Java API for XML Processing (JAXP). JAXP is a standard interface for
processing XML with Java applications. It supports the DOM and SAX standards.
Document Type Definition (DTD). An XML DTD defines the legal structure of an
XML document.
XML Schema. Like a DTD, an XML schema defines the legal structure of an
XML document.
XML Namespaces. Namespaces are a mechanism for differentiating element
and attribute names.
Binary XML. Both scalable and nonscalable DOMs can save XML documents in
this format.

XML Parsing in Java


XMLParser is the abstract base class for the XML parser for Java. An instantiated parser invokes the
parse() method to read an XML document.
XMLDOMImplementation factory methods provide another method to parse Binary XML to create
scalable DOM.
Figure 4-1 illustrates the basic parsing process, using XMLParser. The diagram does not apply to
XMLDOMImplementation().
Figure 4-1 The XML Parser Process

Description of "Figure 4-1 The XML Parser Process"

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 in XML Parsing


DOM builds an in-memory tree representation of the XML document. For example, the DOM API receives
the document described in Example 4-1 and creates an in-memory tree as shown in Figure 4-2. DOM
provides classes and methods to navigate and process the tree.
In general, the DOM API provides the following advantages:

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:

Plug-in Data allows external XML representation to be directly used by Scalable


DOM without replicating XML in internal representation.
Scalable DOM is created on top of plug-in XML data through the Reader and
InfosetWriter abstract interfaces. XML data can be in different forms, such as Binary
XML, XMLType, and third-party DOM, and so on.
Transient nodes. DOM nodes are created lazily and may be freed if not in use.
Binary XML
The scalable DOM can use binary XML as both input and output format. Scalable
DOM can interact with the data in two ways:
Through the abstract InfosetReader and
InfosetWriter interfaces. Users can (1) use the BinXML implementation
of InfosetReader and InfosetWriter to read and write BinXML data,
and (2) use other implementations supplied by the user to read and write in
other forms of XML infoset.
Through an implementation of the InfosetReader and
InfosetWriter adaptor for BinXMLStream.

SAX in the XML Parser


Unlike DOM, SAX is event-based, so it does not build in-memory tree representations of input documents.
SAX processes the input document element by element and can report events and significant data to
callback methods in the application. The XML document in Example 4-1 is parsed as a series of linear
events as shown in Figure 4-2.
In general, the SAX API provides the following advantages:

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"

JAXP in the XML Parser


The JAXP API enables you to plug in an implementation of the SAX or DOM parser. The SAX and DOM
APIs provided in the Oracle XDK are examples of vendor-specific implementations supported by JAXP.
In general, the advantage of JAXP is that you can use it to write interoperable applications. If an
application uses features available through JAXP, then it can very easily switch the implementation.
The main disadvantage of JAXP is that it runs more slowly than vendor-specific APIs. In addition, several
features are available through Oracle-specific APIs that are not available through JAXP APIs. Only some
of the Oracle-specific features are available through the extension mechanism provided in JAXP. If an
application uses these extensions, however, then the flexibility of switching implementation is lost.

You might also like