From:             bart at mediawave dot nl
Operating system: Fedora Core 4
PHP version:      5.0.5
PHP Bug Type:     DOM XML related
Bug description:  After inserting a documentFragment it loses its nodes.

Description:
------------
After inserting a documentFragment into a document, the documentFragment
becomes empty / loses its nodes.

I'm not sure if this is by design or not. I searched the W3C DOM spec for
the specified behaviour. But it isn't clear to me if this is the way it
should work or not. I also tested the same code with a normal element in
stead of a documentFragment. Then it does works as I expect.

Also, I'm using PHP 5.0.4 and not PHP 5.0.5 Fedora hasn't released a PHP
5.0.5 package yet. I'm sorry!

Reproduce code:
---------------
<?php 

$xml = '<root><sometag>The quick brown fox jumps over the lazy
dog</sometag></root>';

$doc = new DOMDocument();
$doc->loadXML($xml);

$sometags = $doc->getElementsByTagName('sometag');

while($sometag = $sometags->item(0)) {

        $docFrag = $doc->createDocumentFragment();

        while ($childNode = $sometag->firstChild) {
                $docFrag->appendChild($childNode);
        }

        echo 'Print documentFragment contents before replacing:<br />';
        foreach ($docFrag->childNodes as $childNode) {
                echo 'textContent:', $childNode->textContent, '<br />';
        }

        $sometag->parentNode->replaceChild($docFrag, $sometag);

        echo '<br />Print documentFragment contents after replacing:<br />';
        foreach ($docFrag->childNodes as $childNode) {
                echo 'textContent:', $childNode->textContent, '<br />';
        }
}

?>

Expected result:
----------------
Print documentFragment contents before replacing:
textContent:The quick brown fox jumps over the lazy dog

Print documentFragment contents after replacing:
textContent:The quick brown fox jumps over the lazy dog


Actual result:
--------------
Print documentFragment contents before replacing:
textContent:The quick brown fox jumps over the lazy dog

Print documentFragment contents after replacing:

-- 
Edit bug report at http://bugs.php.net/?id=34836&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=34836&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=34836&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=34836&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=34836&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=34836&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=34836&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=34836&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=34836&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=34836&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=34836&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=34836&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=34836&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=34836&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=34836&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=34836&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=34836&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=34836&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=34836&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=34836&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=34836&r=mysqlcfg

Reply via email to