php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44814 cannot properly return DOMDocumentFragment
Submitted: 2008-04-24 04:11 UTC Modified: 2008-04-24 17:05 UTC
From: anthony at createvibe dot com Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.2.5 OS: linux
Private report: No CVE-ID: None
 [2008-04-24 04:11 UTC] anthony at createvibe dot com
Description:
------------
When I create a document fragment via, DOMDocument::createDocumentFragment() and append child nodes to this fragment (not sure if the 2nd step is crucial to reproducing this bug), then try to return the document fragment and then try to append that fragment to another DOMDocument, I receive a DOMException / Wrong Document error.

Reproduce code:
---------------
function get_frag()
{
	$dom = new DOMDocument;
	$frag = $dom->createDocumentFragment();
	$frag->appendChild( $dom->createElement('br') );
	return( $frag );
}
$dom = new DOMDocument;
$dom->appendChild( get_frag() );
echo $dom->saveXML();

Expected result:
----------------
<?xml version="1.0"?>
<br/>

Actual result:
--------------
( ! ) DOMException: Wrong Document Error in ... test_bug.php on line 10
Call Stack
#	Time	Memory	Function	Location
1	0.0004	62056	{main}( )	../test_bug.php:0
2	0.0006	63780	DOMNode->appendChild( class DOMDocumentFragment { } )	../test_bug.php:10
Dump $_SERVER

$_SERVER['REQUEST_URI'] =

	

string '/test_bug.php' (length=13)

Variables in local scope (#1)

$dom =

	

object(DOMDocument)[1]


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-04-24 12:32 UTC] chregu@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

You need to import every node, if you want to use it in another 
document.

$dom->appendChild( $dom->importNode(get_frag(),true) );

works in your example
 [2008-04-24 17:05 UTC] anthony at createvibe dot com
Thank you!  I tried to importNode in my application, but not in my example.  The importNode didn't work for some reason, but seeing that it does work in my small example, I'll figure it out from there.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 20:01:28 2024 UTC