|
Posted by Tobias Tom on 03/02/05 15:03
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 );
?>
Navigation:
[Reply to this message]
|