Section 10.1. A Tale of Two Interfaces


10.1. A Tale of Two Interfaces

When the W3C released the first version of the DOM, the organization also released two different APIs: the Core and the HTML API.

The DOM Core is a language- and model-neutral API that can be implemented in any language, not just JavaScript, and for any XML-based model, not just XHTML. As such, it literally is the core of the DOM.

Prior to the release of the DOM specification, though, browsers had already implemented the Browser Object Model in various forms, some proprietary and some not. To maintain a level of compatibility with previous work, the W3C also released a custom subset of the DOM API: The DOM HTML API.

The DOM HTML API is an object-oriented, hierarchical view of the web page, with objects mapped to HTML elements: HTMLDocumentElement for the document, HTMLBodyElement for the body, and so on. Using it is very similar to how we used the BOM in the last chapter. The primary difference between the twoBOM API and DOM HTML APIis that the W3C's is an attempt to formalize an approach that works with all browsers. The W3C also extended the API to make it more compatible with the underlying Core API.

The Core API is a generic API that, as I just mentioned, can work with any form of standard XML. It consists of objects such as Node and nodeLists, Attr, Element, and the all-important Document. The Core API also provides a basic set of data types and expected behaviors that agents such as browsers must support, though much of this support is not obvious when working with JavaScript.

The HTML API shows only in the first two W3C releases. The reason is that the additions and modifications documented in the W3C DOM Level 3 are specific to the Core API; the HTML API wasn't directly impacted. However, the HTML API is as valid as the Core. As such, you can use either the Core, HTML, or both as needed.

A good source for an overview of the different DOM specifications is the OASIS Cover Pages article, at http://xml.coverpages.org/dom.html.





Learning JavaScript
Learning JavaScript, 2nd Edition
ISBN: 0596521871
EAN: 2147483647
Year: 2006
Pages: 151

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net