|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32011 Fragments witch replaced Nodes are not globaly useable
Submitted: 2005-02-17 16:17 UTC Modified: 2005-02-18 12:50 UTC
From: clynx at succont dot de Assigned:
Status: Closed Package: DOM XML related
PHP Version: 5.0.3 OS: FreeBSD 4.11
Private report: No CVE-ID: None
 [2005-02-17 16:17 UTC] clynx at succont dot de
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:
$xmlData = <<<XMLCONTENT
<?xml version="1.0" encoding="utf-8"?>
    <replace />

$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"?>

Actual result:
replacement tags found: 1

xml code used:
<?xml version="1.0" encoding="utf-8"?>


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-18 12:50 UTC]
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
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue Jul 05 06:05:45 2022 UTC