#31484 [Opn->Bgs]: Strage behaviour when looping through a NodeList
ID: 31484
Updated by: chregu@php.net
Reported By: clynx at users dot sourceforge dot net
-Status: Open
+Status: Bogus
Bug Type: DOM XML related
Operating System: FreeBSD 4.11
PHP Version: 5.0.3
New Comment:
Sorry, but your problem does not imply a bug in PHP itself. For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions.
Thank you for your interest in PHP.
A nodelist is a so called "live" collection. Meaning, if you remove an
element from it, nodelist->length will be one less. This should explain
your behaviour.
Previous Comments:
------------------------------------------------------------------------
[2005-01-11 01:56:21] clynx at users dot sourceforge dot net
updated libxml2 to 2.6.16, same error
------------------------------------------------------------------------
[2005-01-11 01:30:34] clynx at users dot sourceforge dot net
Description:
------------
I want to use a complete Namespace to execute self written PHP
Classes.
My Parser has some Problems with the way PHP handles the Code.
It seems like my code handles all dom Functions right, but the Result
is not the one I would expect.
Reproduce code:
---------------
<?php
$dom = new DOMDocument();
$dom->load("http://www.succont.de/php/domxml.xml");
$nodelist=$dom->getElementsByTagNameNS( 'http://test.de/test', '*' );
for($i = 0; $i < $nodelist->length; $i++)
{
$node = $nodelist->item($i);
if($node->localName == "test")
{
$node->parentNode->removeChild($node);
echo $node->localName . " removed \n";
} else {
echo 'handle: ' . $node->localName . "\n";
}
}
echo "\nXML File:\n".$dom->saveXML();
?>
Expected result:
----------------
bash-2.05a$ php -q test.php
handle: doSomething
test removed
handle: doSomething
XML File:
<?xml version="1.0" encoding="utf-8"?>
<example xmlns:test="http://test.de/test">
<test:doSomething/>
<test:doSomething/>
</example>
Actual result:
--------------
bash-2.05a$ php -q test.php
handle: doSomething
test removed
XML File:
<?xml version="1.0" encoding="utf-8"?>
<example xmlns:test="http://test.de/test">
<test:doSomething/>
<test:doSomething/>
</example>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=31484&edit=1
Thread (4 messages)