note 61804 added to function.domnode-clone-node
| From: | andrewattransitionmediadotcodotuk at osu1 dot php dot net | Date: | Sun, 12 Feb 2006 15:04:23 +0000 |
| Subject: | note 61804 added to function.domnode-clone-node | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-103568@lists.php.net to get a copy of this message | ||
As of version 4.3 PHP doesn't support Appending a child from another source document. If you
are trying to import information from multiple sources into a final document [for transformation
using XSL as an example] then you can have problems. This technique can be used to do it though.
I am assuming you have two documents open, $xmldoc1 and $xmldoc2 and you have selected [via XPath or
explicit searching] the nodes you want in each document. Thus $xmldoc1_appending_node is the node
you would like to add $xmldoc2_importnode to.
<?
// first we create a temporary node within the document we want to add to.
$temp_importnode = $xmldoc1->create_element("import");
// now we have a node that is in the right document context we can clone the one we want into this
one.
$temp_importnode = $xmldoc_importnode->clone_node(true);
// by using true in the above call to clone_node() we copy all of the child nodes as well. Use false
or nothing if you just want the containing node with no children.
$xmldoc1_appending->append_child($importnode);
?>
Now your document contains the new nodes imported from a different document.
----
Server IP: 64.246.30.37
Probable Submitter: 80.1.224.9 (proxied: 82.22.1.116)
----
Manual Page -- http://www.php.net/manual/en/function.domnode-clone-node.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+61804
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61804&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61804&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61804&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61804&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61804&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61804&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61804&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+61804&report=yes
Search -- http://master.php.net/manage/user-notes.php