#34836 [Opn->Asn]: After inserting a documentFragment it loses its nodes.

From: Date: Wed, 12 Oct 2005 10:54:04 +0000
Subject: #34836 [Opn->Asn]: After inserting a documentFragment it loses its nodes.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-86451@lists.php.net to get a copy of this message
ID: 34836 Updated by: tony2001@php.net Reported By: bart at mediawave dot nl -Status: Open +Status: Assigned Bug Type: DOM XML related Operating System: Fedora Core 4 PHP Version: 5.0.5 -Assigned To: +Assigned To: rrichards New Comment: Assigned to the maintainer. Previous Comments: ------------------------------------------------------------------------ [2005-10-12 12:21:37] bart at mediawave dot nl 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 this bug report at http://bugs.php.net/?id=34836&edit=1

« previous php.bugs (#86451) next »