DOM Level 2

We've gone through all the interfaces of the DOM Level 1. Now we are going to take a quick look at the other levels of the DOM specification.

We will not be able to explore them thoroughly, but when we are finished, you will be oriented in most of the specifications and will know where to get the additional information you may need.

Level 2 of the DOM was approved by the W3C as a W3C Recommendation in November 2000. The full specification can be found at the official Web site of the consortium at http://www.w3.org/TR/DOM-Level-2-Core. Since the release of the specification, software vendors have started incorporating support for DOM 2 into browsers (IE 5.5 and later, Netscape 6), DOM parsers, and APIs. The Java 2 Standard Edition, Version 1.4, includes support for Level 2. Later in this chapter, we will discuss the tools and levels of the DOM they support.

The DOM Level 2 is an extension to Level 1 specification and it defines all the interfaces found in it, but also extends them with some extra features. These features are

  • Events

  • Views

  • Styles

  • Traversal and Ranges

The Level 2 specification has also introduced some changes to the core interfaces defined in Level 1.

Modifications to the Core Interfaces

The specification of the DOM Level 2 Core builds on the DOM Level 1, meaning that almost all the interfaces and methods that are present in Level 1 can also be found in Level 2. However, as the specification introduces new functionality, some changes have been made to the core interfaces. The specification discusses the differences between Level 1 and Level 2 in detail, which we will examine briefly.

The following changeshave been made to the Core Interfaces in Level 2:

  • Attr— The Attr node has an additional property that references to its owner Element.

  • Document— The Document interface has five extra methods, which are useful to work with Namespaces and move nodes from one document to another.

  • NamedNodeMap— Three more methods have been added to make it easier to use Namespaces.

  • Node— The Node interface now has three more properties and two extra methods. It is now possible to determine whether a particular node supports a feature and whether it has attributes.

  • DocumentType— This interface has been extended with three more properties.

  • DOMImplementation— This interface now allows creating new documents with association to a specific Namespace and document type. A factory for empty DocumentType nodes has also been added.

  • Element— This is the most affected interface as it has eight new methods mostly for operating with Namespaces.

  • DOMException— New exception codes have been added.

Note

The feature string corresponding to the set of core interfaces in a call to DOMImplementation.hasFeature() method is “Core” and the version for any Level 2 feature is “2.0.”


Supplemental Specifications

The DOM Level 2 specification is separated into 14 modules that support particular groups of features. Unlike the DOM Level 1, the Level 2 allows implementers to implement only the modules they need (the core module still has to be implemented).

Events

The first of the modules is an Events module, which describes the event model for the DOM. There are several types of events (UI events, mouse events, and so on) and an implementation can support some or all of them.

The source of any event in the DOM is always a document processor. The Events module provides developers with interfaces and methods to register their event targets and listeners and handle them according to their needs.

Note

The feature string corresponding to the event model in a call to DOMImplementation.hasFeature() method is “Events” and the version is “2.0.” For particular types of events, it is also possible to call this method with the following strings:

  • UIEvents

  • MouseEvents

  • MutationEvents

  • HTMLEvents


Views

The same XML document can be presented to a user in multiple ways. The presentation of a document can change in response to any changes to the document. To make it easier to associate views with an XML document, there is a “Views” module in the Level 2 specification.

The implementation of actual views is beyond the scope of the specification, so it is really just a foundation for implementing custom views, which gives a standard way of associating them with documents.

Note

The feature string corresponding to the event model in a call to DOMImplementation.hasFeature() method is “Views,” and the version is “2.0.”


Styles

The styles section of the Level 2 specification defines a standard way of associating documents with style sheets of any kind. The Styles module contains just a few base interfaces that can be extended by a developer.

Note

The feature string corresponding to the event model in a call to DOMImplementation.hasFeature()method is “Styles” and the version is “2.0.” For particular features, it is also possible to call this method with the following strings:

  • StyleSheets

  • CSS

  • CSS2


Traversal

The traversal module defines a few handy interfaces for traversal of XML documents, such as NodeIterator, TreeWalker, and NodeFilter.

Note

The feature string corresponding to the event model in a call to DOMImplementation.hasFeature()method is “Traversal,” and the version is “2.0.”


Range

Finally, the Range section of the DOM Level 2 specification defines could be handy for implementing applications that operate with ranges of data in an XML document.

Interfaces implemented in the Range module are useful, for example, for selecting, copy-pasting, deleting, and so on, of ranges of Elements in a document.

Note

The feature string corresponding to the event model in a call to DOMImplementation.hasFeature() method is “Range,” and the version is “2.0.”


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.134.79.121