You are here: DOM: copying from one document to another « PHP « IT news, forums, messages
DOM: copying from one document to another

Posted by "Chris Boget" on 06/01/05 21:34

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

 

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

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