W3C home > Mailing lists > Public > www-dom@w3.org > January to March 2001

Traverse and Node types

From: Martijn Pieters <mj@digicool.com>
Date: Sat, 24 Feb 2001 12:44:19 +0100
To: www-dom@w3.org
Message-ID: <20010224124418.A21798@zopatista.com>

I am trying to find out what Node types are actually iterated over when
using a NodeIterator or TreeWalker on a DOM tree.

The NodeFilter Interface lists all possible Node types to filter out with
the whatToShow attribute of the TreeWalker and NodeIterator Interfaces.
From this (and other references), one can extrapolate that both these
Interfaces will normally visit *all* possible Node types in a DOM tree.

However, a naive implementation of TreeWalker or NodeIterator will use
only the .childNodes, .firstChild, .lastChild, .nextSibling,
.previousSibling and .parentNode attributes of the Node interface. Using
these methods, no Attr, Entity or Notation Nodes will ever be encountered,
nor will any of the Nodes making up the sub-trees of Attr and Entity

If however an implementation wants to include these 'lost' Node types by
including DocumentType.entities and .notations, and Node.attributes,
another problem arises; that of ordering. The Traversal interface
specifies that the .nextNode() and .previousNode() methods iterate over
Nodes in document order. 

But what is document order for the .attributes Nodes of an Element? The
NamedNodeMap doesn't preserve ordering. And DocumentType.entities and
.notations are not only NamedNodeMaps, any document ordering as these
Nodes are not modeling the actual definitions in the DTD. Should we first
iterate .entities or .notations?

For .attributes and .childNodes it is clearer, attributes come before
child Nodes in document order, so TreeWalker.firstChild will then take an
Attribute Node first if there are any available.

Can anyone shed some light on this issue? Should Attr, Entity and Notation
Nodes be included in DOM tree traversals? And if so, how are .attributes,
.entities, .notations and .childNodes collections ordered?

Whatever the answer, I think the Traversal specification could do with an
explicit explanation on this issue.

Martijn Pieters
| Software Engineer  mailto:mj@digicool.com
| Digital Creations  http://www.digicool.com/
| Creators of Zope   http://www.zope.org/
Received on Saturday, 24 February 2001 06:44:23 UTC

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