I had exactly the same problem as you've now found out
There is a solution depending on what version of PHP 5 you have? If you have the latest via CVS you need to use a Document Fragment, prior to appending the node.
If on the other hand, like me you're using something like version 5.0.2 you have a more difficult time of things 
Fortunately I found a solution which has helped me out a few times. It works but does involve some extra work for you, here is what I found below
PHP Code:
//! temp function php version 5.0.2
//! append a document fragment to a dom document tree
function appendNode( $phptag, $dom_document, $xml_string ) {
$tag = $dom_document -> getElementsByTagName( $phptag );
$tag = $tag -> item(0);
$tmp = new domdocument();
$tmp -> load( $xml_string );
$node = $tag -> ownerDocument -> importNode( $tmp -> documentElement, true );
$child = $node -> firstChild;
while( $child ) {
$nextChild = $child -> nextSibling;
$tag -> appendChild( $child );
$child = $nextChild;
}
unset( $tmp );
return $tag;
}
And an example to use it
PHP Code:
public function execute( http_request $request ) {
$this -> page = new DomDocument;
$this -> page -> load( 'templates/home/template.tpl' );
$entries = announcements_gateway::load( announcements_finder::find_all_by_limit( $this -> db, 5 ) );
appendNode( 'phptag-announcements', $this -> page, 'sample.xml' );
}
Hope this helps you, as it helped me a lot
Bookmarks