You are here: PHP5 DOM - DomDocumentFragments empty « PHP « IT news, forums, messages
PHP5 DOM - DomDocumentFragments empty

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация