DOM: copying from one document to another

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux