php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: clynx at succont dot de
New email:
PHP Version: OS:

 

 [2005-02-17 16:17 UTC] 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>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-18 12:50 UTC] rrichards@php.net
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.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 15:01:30 2024 UTC