php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32163 New Fragment has Empty Content
Submitted: 2005-03-02 15:31 UTC Modified: 2005-03-02 23:18 UTC
From: clynx at succont dot de Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5CVS-2005-03-02 (dev) OS: FreeBSD 4.11
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: clynx at succont dot de
New email:
PHP Version: OS:

 

 [2005-03-02 15:31 UTC] clynx at succont dot de
Description:
------------
When creating a new DocumentFragment, and appending some Child Nodes, the Fragment is still Empty. The Content is inside the DomDocument, but cannot be accessed through the Fragment Node.

Reproduce code:
---------------
<?php
$xmlData = <<<XMLDATA
<?xml version="1.0" encoding="ISO-8859-1" ?>
<root>
	<subElement>content</subElement>
</root>
XMLDATA;

$dom = new DomDocument;
$dom->loadXML( $xmlData );

$dom2 = new DomDocument;
$fragment = $dom2->createDocumentFragment();
foreach( $dom->childNodes AS $node ) {
	$newNode = $dom2->importNode( $node, true );
	$fragment->appendChild( $newNode );
}
$dom2->appendChild( $fragment );

echo $dom2->saveXML( $fragment );
?>

Expected result:
----------------
<root>
	<subElement>content</subElement>
</root>

Actual result:
--------------
no output (empty String is returned)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-03-02 15:56 UTC] rrichards@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Appending fragment removes the nodes from the fragment. Otherwise it breaks xsl, xpath and unexpected tree navigation results.
 [2005-03-02 17:27 UTC] clynx at succont dot de
Sorry for answering here, but what is the sense of these Fragments then? Appending an Empty Fragments throws an Error that "Document Fragment is empty".
When Inserting the Fragment removes the Childs, these Object is not really usable, or am I wring here?

Just a second thing which comes in my mind. Why does $dom2->saveXML() shows the complete Structure like it should be?

Thanks for your time
 [2005-03-02 22:27 UTC] clynx at succont dot de
Just read inside the W3 Recommendation, because the Manual tells that is Extension follows the Standard as most as possible.
Now I think that this behaviour is not correct after the Standard.
It exactly says 'When a DocumentFragment is inserted into a Document ... the children of the DocumentFragment and not the DocumentFragment itself are inserted into the Node.'. Currently this is not the case in PHP.

I've read your comment about XSL problems, and I think you are talking about a bug which was submitted by me, too. 
IMHO it's no solution to switch the Feature of to Fix a Bug.

Maybe I'm completly wrong. If so, please forgive me. Please give me some Information how this should be done in the right way. The Support in this Extension is a little bit rare out there ;o)

Regards
 [2005-03-02 23:18 UTC] rrichards@php.net
And the children (not the fragment) are inserted into the document. This means that the children now have a new parent node which is no longer the fragment. In this case we cant have two different nodes pointing to the same child, so the fragment must loose its children. Contact me outside the bug system if you have questions on this as this behavior is not a bug.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 08:01:32 2024 UTC