ID:               42282
 Updated by:       [EMAIL PROTECTED]
 Reported By:      TomTrnka at seznam dot cz
-Status:           Open
+Status:           Bogus
 Bug Type:         DOM XML related
 Operating System: Linux
 PHP Version:      5CVS-2007-08-13 (snap)
 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

nodelists are live and updated as nodes are removed from them


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

[2007-08-13 09:44:05] TomTrnka at seznam dot cz

Description:
------------
When a node tree is copied from one DOMDocument to another using 
recursive importNode on the tree root and then copying the 
childNodes in a loop (doesn't matter whether for or foreach) using 
e.g. appendChild, the loop is no more repeated after copying the 
first element, that means, other child elements do not get copied.
Additionally, the source childNodes->length gets decremented.

The opposite approach - iterating through the source elements and 
importing&appending one at a time works flawlessly.

On commenting out the appendChild call the iteration goes normally, 
too.

Reproduce code:
---------------
<?php
error_reporting(E_ALL | E_STRICT);
$srcdoc = new DOMDocument("1.0", "UTF-8");
$src = $srcdoc->appendChild($srcdoc->createElement("srcroot"));
$src->appendChild($srcdoc->createElement("elem1", "1"));
$src->appendChild($srcdoc->createElement("elem2", "2"));

echo $srcdoc->saveXML();

$dstdoc = new DOMDocument("1.0", "UTF-8");
$dst = $dstdoc->appendChild($dstdoc->createElement("dstroot"));


$tmp = $dstdoc->importNode($src, TRUE);
echo $tmp->childNodes->length;

foreach ($tmp->childNodes as $child) {
        echo ".";
        $dst->appendChild($child);
}
echo "\n";

echo $dstdoc->saveXML();
?>

Expected result:
----------------
The output should look like this (both elements copied):

<?xml version="1.0" encoding="UTF-8"?>
<srcroot><elem1>1</elem1><elem2>2</elem2></srcroot>
2..
<?xml version="1.0" encoding="UTF-8"?>
<dstroot><elem1>1</elem1><elem2>2</elem2></dstroot>


Actual result:
--------------
The output looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<srcroot><elem1>1</elem1><elem2>2</elem2></srcroot>
2.
<?xml version="1.0" encoding="UTF-8"?>
<dstroot><elem1>1</elem1></dstroot>

That means the elem2 did not get copied. There is also only one dot 
at the "2." row, meaning the second iteration of the loop hasn't 
even started.


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


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

Reply via email to