On Tuesday, 10/28/2003 at 09:59 PST, "Jeff Greif"
<[EMAIL PROTECTED]> wrote:
> A completely portable, low-tech, arms-length solution would be to
construct
> the document, then traverse it to construct one or both of the Maps,
> Node->Id and Id->Node, assigning the Id as you go.
Unfortunately, before DOM Level 3 there is no really good way to build a
complete Node-to-arbitrary-data map. The DOM API doesn't guarantee that
node identity implies object identity (that is, there may be more than one
Node object representing the same DOM Node), nor does it support hashing.
You can try to do something with adding magic attributes to the elements to
carry this info, but non-Element nodes are still a challenge. The most
general solution is to calculate what amounts to XPaths for every node and
index the map by those... which is fragile if you plan to edit the DOM's
contents; essentially, you wind up maintaining a parallel tree, which gets
ugly.
Which is why DOM Level 3 -- as of the last time I checked, anyway -- is
planning to introduce both the userData() hook and the isSameNode() test.
The latter closes the oversight of not having a way to ask whether two Node
objects are the same DOM Node; the former provides a general/encapulated
way to maintain this sort of side information without having to deal with
parallel trees or implementation-specific characteristics.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]