#31484 [Bgs]: Strage behaviour when looping through a NodeList
| From: | clynx at users dot sourceforge dot net | Date: | Tue, 11 Jan 2005 08:18:20 +0000 |
| Subject: | #31484 [Bgs]: Strage behaviour when looping through a NodeList | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-71835@lists.php.net to get a copy of this message | ||
ID: 31484
User updated by: clynx at users dot sourceforge dot net
Reported By: clynx at users dot sourceforge dot net
Status: Bogus
Bug Type: DOM XML related
Operating System: FreeBSD 4.11
PHP Version: 5.0.3
New Comment:
Tried to get Support, but most of them did not know new dom, or thought
the behaviour should be as i expected.
Thank you for your answer, and sorry for buging. ;o)
Previous Comments:
------------------------------------------------------------------------
[2005-01-11 08:19:57] chregu@php.net
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.
------------------------------------------------------------------------
[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