XUL in Firefox: The Document Object Model (DOM)




Any manipulation of an XML structured document relies on the DOM as defined by the World Wide Web Consortium (W3C). The W3C defines several layers of DOM specifications that build upon one another:

DOM Level 1

Level 1 defines the structure of XML documents, including XML-formatted HTML documents (technically referred to as XHTML documents). The core DOM 1 specification provides the initial description of document nodes, how to access them, and how to change the structure of a document by adding and removing nodes from the DOM document tree. Also part of DOM Level 1 is the description of HTML Elements, including the methods to access and manipulate structural aspects of the document tree representing an HTML document.

DOM Level 2

The Level 2 core specifications add namespaces and the concept of document views, and fully specify the event model, stylesheet manipulation, and document traversal interfaces. The Level 2 HTML Element specification adds a number of interfaces that provide additional utility methods to process HTMLspecific elements.

DOM Level 3

The Level 3 specification adds features for managing document state and supporting document validation. Although most of the topics relevant to our discussion involve DOM Level 2 and earlier, there is no substantive difference in functionality among the different levels, only extensions or enhancements in functionality.

Interfaces

Whereas an object represents a collection of methods (functions) and properties (data members) that model an entity, an interface represents a collection of methods and properties that are bound by related characteristics. Consider a nonsoftware example:

A Subaru Outback may represent an object of a class named "all-wheel-drive cars."

We could also describe the class of "all-wheel-drive cars" as implementing several interfaces:
• The rolling interface for vehicles that have four wheels, tires, and brakes
• The gasoline-fueled interface that provides methods for fueling and combustion
• The passenger-carrier interface for the characteristics of cabin size, interior climate control, and safety features

A delivery truck, on the other hand, would implement a rolling interface, but would probably also implement a cargo-carrier and diesel-fueled interface. Rolling, gasoline-fueled, and passenger-carrier collections don't, by themselves, provide sufficient information to create a meaningful object. An object that implements an interface, however, can use the interface's methods and properties to provide a type of needed functionality.

As an example relevant to XUL and DOM, I will describe references that implement a node interface which, in turn, also implements an element interface. This means that the object referenced will implement functions that are related both to the document structure (node characteristics), and to information such as style, tag name, and attributes (element characteristics).

In summary, interface is best thought of as a well-defined characteristic of an object implemented through a set of related functions and properties.

If you want to continue learning about XUL programming in Firefox or if you want to find more about programming languages, please visit http://www.missingcode.com

Article Source: http://EzineArticles.com/6303817