PHP5 DOM - DomDocumentFragments empty

From: Date: Wed, 02 Mar 2005 13:03:23 +0000
Subject: PHP5 DOM - DomDocumentFragments empty
Groups: php.general 
Request: Send a blank email to php-general+get-209796@lists.php.net to get a copy of this message
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 ); ?>

« previous php.general (#209796) next »