XML technologies / XML / Python & XML / The Document Object Model / The DOM specifications
(Excerpt from “Python & XML” by Christopher A. Jones & Fred L. Drake, Jr.)
W3C recommendations define DOM. They cover XML extensively, but other subjects too. DOM originated in HTML: browser vendors invented variants for client-side scripting APIs. Their different interfaces prompted content authors to demand a standard so pages would behave at least roughly alike across browsers. The W3C offers the best common ground for vendors, so it develops the DOM specifications.
Standards bodies struggle with specifications’ longevity, and the W3C is no exception despite being young compared with ANSI and ISO. Rapid Internet standardization and implementation forced it to confront this early. It nevertheless follows a more traditional model than the informal, effective one behind the Internet Engineering Task Force (IETF).
Most W3C recommendations use the software-style version numbering major.minor, perhaps reflecting the organization’s origins. HTML illustrates this: many differing versions have appeared. Documents with more than basic content rarely conform to several versions. This seems hard to avoid for markup languages, but makes standards less valuable than greater version independence could allow.
DOM takes a different approach: its specifications do not have versions in HTML’s sense. The same model is used for Cascading Style Sheets (CSS), beyond this book’s scope.
DOM is a family of individual specifications described along two axes: breadth and depth. Breadth describes the range of functionality; depth describes detail and underlying functionality. The W3C calls functional areas features and detail depth levels.
Specification levels
It is useful to explain levels first, since they confuse many people. Often described as another word for versions, they are quite different. Unfortunately, DOM specifications are not always clear about this. Improved features introduce new levels, encouraging confusion with versions. The crucial difference is that level 2 must include level 1: advancing preserves compatibility with code expecting the older specification.
Each level spans the DOM family as it existed when defined, with one exception. Later levels add features. Implementations need not support all features, but generally support their chosen features at the same level.
At writing time, two levels were recommendations and a third was under development. Prestandard browser interfaces are often called “Level 0.” Level 1 is one recommendation defining Core and HTML, supporting HTML and XML 1.0 only. Level 2 splits into six documents, divides Core into Core and XML, and supports namespaces. New features include events, mainly but not exclusively for browsers, CSS, traversal, ranges and vague document views. Oddly, level 2 HTML remained unfinished with no visible progress for some time.
Level 3, still only working drafts, currently has four documents. Core, XML and events are refined, but new features are most interesting: schemas supporting at least DTD and XML Schema, XML loading and saving, and an object model for XPath expressions. We discuss XPath in Querying XML with XPath, but its DOM feature is not ready for use yet.
Specifying features
DOM’s features vary by level, adding new ones or dividing existing ones. New features do not disturb code using earlier levels. Dividing features has not caused practical problems either, if only because level 2 implementations support both Core and XML. Only Core is mandatory for all implementations.
Most Python DOM implementations support some level 2 features, while level 3 remains a draft. Let us examine what each level 2 feature offers developers.
Core
Basic structures expose well-formed XML without DTD information. In particular, entities, notations, entity references and processing instructions are absent. These are the interfaces examined here.
XML
Adds interfaces representing entity and notation declarations from the document type declaration, but not the document type itself, plus lexical information useful when writing modified documents: CDATA sections, entity references and processing instructions.
Events
Divides into specific subfeatures. Any event-supporting implementation must support the basic event feature, but only meaningful subfeatures. These include user-interface event classes and document-mutation events.
Ranges
Describes parts not representable as sequences of nodes, useful for a portion highlighted by a user.
Traversal
Supports traversal in document order or as a tree, moving a cursor among children, parents and siblings. Filters can hide nodes irrelevant to the application.
Views
A vague specification aiming to provide several document views, not necessarily useful.
StyleSheets
An abstract stylesheet interface, not tied to CSS and usable for other languages. Since languages differ greatly, it exposes little styling information.
CSS
Extends the stylesheet interface with extensive CSS2 information. Browsers and editors should use it to update presentation when stylesheets change.
Additional DOM features for specific XML languages are developed outside the DOM working group. Information and group specifications are at Document Object Model (DOM) Technical Reports.
Copyright © 2002 O'Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from “Python & XML” is subject to the same conditions as the bound edition: the work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de