PHP5 DOM - DomDocumentFragments empty

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I've a Problem with the DOM Extension in PHP5. I simply want to create
a DocumentFragment which can be used in ImportNode for Example. I now
that the code beyond may look a little bit strange, but I've
simplyfied it as much as it was possible.

The Code should print the Contents of the the Fragment which is Part
of the DomDocument. When you run this Code you'll see that the Result
is an empty String.

Does anyone has any Idea is this behaviour is correct, or if this
might be a PHP Bug.
If I'm doing something wrong, could you please tell me what's wrong?

Thank you for your Help.

Regards

Tobias

<?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 );
?>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux