DOM: copying from one document to another

From: Date: Wed, 01 Jun 2005 18:34:30 +0000
Subject: DOM: copying from one document to another
Groups: php.general 
Request: Send a blank email to php-general+get-216160@lists.php.net to get a copy of this message
Consider the following test code: <script language="php"> $doc = domxml_new_doc( '1.0' ); $baseDocument = domxml_new_doc( '1.0' ); $domNode = $doc->create_element( 'Node' ); $node = $doc->create_element( 'NodeChild' ); $textNode = $doc->create_text_node( 'this' ); $node->append_child( $textNode ); $domNode->append_child( $node ); $doc->append_child( $domNode ); $node = $doc->create_element( 'AnotherNode' ); $childNode = $doc->create_element( 'AnotherNodeChild' ); $textNode = $doc->create_text_node( 'that' ); $childNode->append_child( $textNode ); $node->append_child( $childNode ); $domNode->append_child( $node ); $doc->append_child( $domNode ); $elements = $doc->get_elements_by_tagname( '*' ); $element = $elements[0]; $child = $element->first_child(); while( $child ) { $baseDocument->append_child( $child ); $child = $child->next_sibling(); } </script> When I run it, I am presented with the error: Warning: append_child(): Can't append node, which is in a different document than the parent node in test_dom.php on line 31 Is there any way I can copy an element from one DOM document to another without having to dissect the original node/element and create a new node/element from scratch using the new DOM document and append to it? thnx, Chris

« previous php.general (#216160) next »