You are on page 1of 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
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:

However. In general. Use a SAXParser object to parse with SAX. can be performed. the DOM API provides the following advantages: ● DOM API is easier to use than SAX because it provides a familiar tree structure of objects. which means that a program cannot access random locations in a document. Example 4-1 Sample XML Document <?xml version="1. most XPath implementations use DOM. and renaming elements. ● A pluggable. The sample XML document in Example 4-1 helps illustrate the differences among DOM. the DOM API receives the document described in Example 4-1 and creates an in-memory tree as shown in Figure 4-2.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. and JAXP. ● DOM as a standard does not support XPath. ● DOM API. scalable DOM. adding to and deleting elements and attributes. ● Structural manipulations of the XML tree. ● Interactive applications can store the object model in memory. which parses XML documents and builds a tree representation of the documents in memory. enabling users to access and manipulate it. The Oracle XDK includes DOM API extensions to support XPath. such as re-ordering elements. and XSL. ● JAXP. which processes an XML document as a stream of events. scalable DOM can be created that considerably improves scalability and efficiency. DOM Creation . DOM provides classes and methods to navigate and process the tree. Use either a DOMParser object to parse with DOM or the XMLDOMImplementation interface factory methods to create a pluggable. SAX. Use a DocumentBuilder or SAXParser object to parse with JAXP. SAX. ● SAX API. For example. which is a Java-specific API that supports DOM.

○ Through an implementation of the InfosetReader and InfosetWriter adaptor for BinXMLStream. and so on. 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.1). there are three ways to create a DOM: ● Parse a document using DOMParser. and third-party DOM.In Java XDK. In general. This is not a common solution in XDK. pluggable support for DOM. This relieves problems of memory inefficiency. Scalable DOM can interact with the data in two ways: ○ Through the abstract InfosetReader and InfosetWriter interfaces. limited scalability. ● Binary XML ● The scalable DOM can use binary XML as both input and output format. XDK provides scalable. ● It is faster than DOM when retrieving XML documents from a database. the configuration and creation are mainly supported using the XMLDOMImplementation class. ● Use an XMLDocument constructor. and lack of control over the DOM configuration. XML data can be in different forms. Users can (1) use the BinXML implementation of InfosetReader and InfosetWriter to read and write BinXML data. SAX is event-based. ● It does not consume significant memory resources. DOM nodes are created lazily and may be freed if not in use. This has been the traditional XDK approach. Scalable DOM With Oracle 11g Release 1 (11. 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. SAX in the XML Parser Unlike DOM. and (2) use other implementations supplied by the user to read and write in other forms of XML infoset. such as Binary XML. ● Transient nodes. For the scalable DOM. ● Scalable DOM is created on top of plug-in XML data through the Reader and InfosetWriter abstract interfaces. XMLType. SAX processes the input document element by element and can report events and significant data to callback methods in the application. . so it does not build in-memory tree representations of input documents. ● Create a scalable DOM using XMLDOMImplementation factory methods. The XML document in Example 4-1 is parsed as a series of linear events as shown in Figure 4-2.

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