[XML-SIG] repost: getElementsByTagName interpretation

Andrew M. Kuchling akuchlin@mems-exchange.org
Fri, 23 Jun 2000 15:27:31 -0400


On Fri, Jun 23, 2000 at 08:34:00PM +0100, Just van Rossum wrote:
>Dumb newbie question: What does "live" mean in this context? Ie. what makes
>a node "live" or not?

NodeLists are live, not nodes.  It means that when you access
element.childNodes and get a list of children, if you then add a child
to element, the list you retrieved will also be updated to include the
new child.  This is easy in Python for childNodes, since childNodes is
probably just a Python list anyway, so you just return the list and
get the liveness property for free.

Where this falls down is .getElementByTagName('X'), which returns a
NodeList containing all 'X' elements in the tree.  If this is live,
then every time you modify the DOM tree by adding, deleting, or moving
an element, you have to ask "Are there any .getElementByTagName()
NodeLists out there that would change as a result of this?"  If you
consider a change that moves or deletes many elements, such as
deleting a chapter from a book, this seems quite expensive and
time-consuming.

-- 
A.M. Kuchling			http://starship.python.net/crew/amk/
Of course I'm here. I've always been here, there, and everywhere.
  -- Envelope Girl sounds rather Kosh-like, in ENIGMA #5: "Lizards and
   Ghosts"