W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2000

Re: Subclassing DOM nodes

From: Joseph Kesselman/Watson/IBM <keshlam@us.ibm.com>
Date: Wed, 11 Oct 2000 12:41:40 -0400
To: "Kevin Jones" <kevinjz@hotmail.com>
Cc: www-dom@w3.org
Message-ID: <OF598E5F65.AF8ACD39-ON85256975.005A8370@pok.ibm.com>

> How does one subclass DOM Nodes? Is the DOMImplementation class used
> to get at a Node factory?

The Document node is the factory for all nodes contained in that document.
You could subclass Document to provide special handling of specific

Note that this is inherently nonportable. First off, the actual
construct-and-configure sequence for the nodes is implementation dependent;
you need to know exactly how your DOM implementation handles this before
you can rewrite the createElement method appropriately. Secondly, and just
as important: When you subclass, you're always subclassing a specific
parent class; to move a subclassing to another DOM, you'd have to edit the
code to change that parent even if all else was the same (which is

Another possible approach,less elegant but more portable, would be a
"lightweight subclassing" scheme. Here, you would annotate "standard" nodes
rather than subclassing them -- eg, by providing one or more tables indexed
by node identity which can be used to retrieve whatever additional
information and/or code you want to associate with it.

The challenge here is that "node identity" is not necessarily the same as
the address of the Node object (eg if your DOM is a proxy for some other
data structure, you might have several objects proxying the same datum and
thus representing "the same node), so it isn't clear what could be used as
an index for those tables. DOM Level 3 is investigating this.

Joe Kesselman  / IBM Research
Received on Wednesday, 11 October 2000 12:42:30 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 20 October 2015 10:46:07 UTC