#32011 [Opn->Csd]: Fragments witch replaced Nodes are not globaly useable
ID: 32011
Updated by: rrichards@php.net
Reported By: clynx at succont dot de
-Status: Open
+Status: Closed
Bug Type: DOM XML related
Operating System: FreeBSD 4.11
PHP Version: 5.0.3
New Comment:
This bug has been fixed in CVS.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2005-02-17 16:17:26] clynx at succont dot de
Description:
------------
DomDocumentFragments witch replaced existing Nodes in a DomDocument is
not globaly useable.
* Create a DocumentFragment on an existing DomDocument.
* Append one (or more) Child to this Fragment
* Replace existing Node with this Fragment
The Methods DomDocument->saveXML() displays the Document in the right
way.
When you use getElementsByTagName, XPath, or e.g. the XSL Extension
these new Elements are not there.
So in the Example the <replacement> will never be useable, only
viewable.
Reproduce code:
---------------
<?php
$xmlData = <<<XMLCONTENT
<?xml version="1.0" encoding="utf-8"?>
<test>
<replace />
</test>
XMLCONTENT;
$dom = new DomDocument;
$dom->loadXML( $xmlData );
$fragment = $dom->createDocumentFragment();
$replacement = $dom->createElement( 'replacement' );
$fragment->appendChild( $replacement );
$additionalNode = $dom->createElement( 'additionalNode' );
$fragment->appendChild( $additionalNode );
foreach( $dom->getElementsByTagName( 'replace' ) AS $node ) {
$node->parentNode->replaceChild( $fragment, $node );
}
echo "replacement tags found: " . $dom->getElementsByTagName(
'replacment' )->length . "\n\n";
echo "xml code used:\n";
echo $dom->saveXML();
?>
Expected result:
----------------
replacement tags found: 0
xml code used:
<?xml version="1.0" encoding="utf-8"?>
<test>
<replacement/><additionalNode/>
</test>
Actual result:
--------------
replacement tags found: 1
xml code used:
<?xml version="1.0" encoding="utf-8"?>
<test>
<replacement/><additionalNode/>
</test>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=32011&edit=1
Thread (2 messages)