#25838 [Bgs]: Dom_Node->child_nodes() is not live as the W3C DOM specification demands

From: Date: Wed, 15 Oct 2003 04:07:11 +0000
Subject: #25838 [Bgs]: Dom_Node->child_nodes() is not live as the W3C DOM specification demands
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-49040@lists.php.net to get a copy of this message
 ID:               25838
 Updated by:       chregu@php.net
 Reported By:      Martin dot Honnen at arcor dot de
 Status:           Bogus
 Bug Type:         DOM XML related
 Operating System: Windows XP
 PHP Version:      4.3.3
 New Comment:

Just for your Information:

Once we have implemented NodeLists in the new ext/dom for PHP5, this
should work as expected by the W3C.


Previous Comments:
------------------------------------------------------------------------

[2003-10-13 05:29:14] Martin dot Honnen at arcor dot de

But the DOM specification says "changes are automatically reflected in
the NodeList, without further action on the user's part". If you have
to call child_nodes() again and again to have it updated then changes
are not automatically reflected in the NodeList. Compare a simple
JavaScript program to be run in Mozilla:

var xmlDocument = document.implementation.createDocument('', '',
null);
var rootElement = xmlDocument.createElement('gods');
xmlDocument.appendChild(rootElement);
var childNodes = rootElement.childNodes;
for (var i = 0; i < 5; i++) {
  var god = xmlDocument.createElement('god');
  god.setAttribute('name', 'god ' + i);
  rootElement.appendChild(god);
  alert(childNodes.length);
}

You will find that childNodes.length is incremented although childNodes
is created outside of the loop.

------------------------------------------------------------------------

[2003-10-12 22:15:27] sniper@php.net

It works fine when you actually set the $childNodes variable inside the
for() loop.


------------------------------------------------------------------------

[2003-10-11 12:23:04] Martin dot Honnen at arcor dot de

Description:
------------
The W3C DOM Level 2 specification at
  http://www.w3.org/TR/DOM-Level-2-Core/core.html#td-live
says about NodeList collections that they should be live, meaning

if a DOM user gets a NodeList object containing the children of an
Element, then subsequently adds more children to that element (or
removes children, or modifies them), those changes are automatically
reflected in the NodeList, without further action on the user's part.

However my test with PHP 4.3.3 and the following settings for DOMXML

DOM/XML 	enabled
DOM/XML API Version 	20020815
libxml Version 	20507
HTML Support 	enabled
XPath Support 	enabled
XPointer Support 	enabled
DOM/XSLT 	enabled
libxslt Version 	1.0.30
libxslt compiled against libxml Version 	2.5.7

shows that the result returned from Node->child_nodes() is not live but
static.

Reproduce code:
---------------
<?php
function dumpDoc ($xmlDocument) {
  echo "<p><pre>\n";
  echo htmlentities($xmlDocument->dump_mem(true));
  echo "</pre></p>\n";
}
$xmlDocument = domxml_new_doc("1.0");
$rootElement = $xmlDocument->create_element("gods");
$xmlDocument->append_child($rootElement);
$childNodes = $rootElement->child_nodes();
echo 'count($childNodes): ' . count($childNodes) . "<br>\n";
$xmlDocument->append_child($rootElement);
for ($i = 0; $i < 5; $i++) {
  $god = $xmlDocument->create_element("god");
  $god->set_attribute("name", "god $i");
  $rootElement->append_child($god);
  dumpDoc($xmlDocument);
  echo 'count($childNodes): ' . count($childNodes) . "<br>\n";
}
?>

Expected result:
----------------
I would expect count($childNodes) to be incremented every time
$rootElement->append_child($god) is called. That is what the W3C DOM
understands to be a live collection, and that is what happens with
conformant DOM implementations (as the one in Mozilla or the one in
SUN's Java SDK 1.4).

Actual result:
--------------
The output with dump_mem shows that child elements are added but the
output of count($childNodes) is always 0.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=25838&edit=1


Thread (4 messages)

« previous php.bugs (#49040) next »