Re: Node Index Number

>We can refer to a node in a collection by index number using the
>item() method.
>Why is there not a way to get a node's index number in relation
>to a collection?.....or is there?

Largely because the DOM doesn't have any concept of "collection" per se.
There are NodeLists and NamedNodeMaps -- but these should probably be
thought of as views of the data, not as actual collection objects which
contain those nodes. The underlying implementation may not be
collection-based; a node's children, for example, may be retained that way,
may be linked-lists, may be accessed as a database query, or anything else
that seemed appropriate to that DOM's developers.

Also, a node may be in many "collections" at once -- for example, you may
have several "deep" NodeLists (from getElementsByTag) and a "shallow"
NodeList  (from getChildren), all of which overlap with each other. If a
Node knows its offset at all (see above) it will probably know only its
offset in the getChildren list. To find its index in other lists or maps,
the DOM would have to search through the view.


It might be possible to optimize this .getIndexOf(Node) operation in some
implementations of NodeList and NamedNodeMap. For that reason, it might be
worth considering adding this call at some point.

I'll add it to the wishlist. If any of the DOM WG/IG members want to be
listed as advocates, drop me a note.


However -- speaking only for myself -- I'm somewhat dubious that this would
be used often enough to be much more than a convenince feature. Especially
given that I expect Level 2's Traversal chapter to largely replace
NodeLists.



______________________________________
Joe Kesselman  / IBM Research


Terry Friesen <tfriesen@mts.net>@w3.org on 07/07/2000 12:22:49 AM

Sent by:  www-dom-request@w3.org


To:   www-dom@w3.org
cc:
Subject:  Node Index Number



We can refer to a node in a collection by index number using the
item() method.
Why is there not a way to get a node's index number in relation
to a collection?.....or is there?

--
Terry

Received on Friday, 7 July 2000 08:28:30 UTC