note 87812 added to domdocument.importnode
| From: | p dot reisinger at gmail dot com | Date: | Tue, 23 Dec 2008 15:32:18 +0000 |
| Subject: | note 87812 added to domdocument.importnode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-148475@lists.php.net to get a copy of this message | ||
method (can be used as a function as well) that joins two xml files. first argument is parent xml
(the one to be inserted into), second child (the one to be inserted) and third is optional argument
that specifies the parent's tag where to insert children xml. If not specified then children is
inserted as the last element, just before end of the root
<?php
protected function joinXML($parent, $child, $tag = null)
{
$DOMChild = new DOMDocument;
$DOMChild->loadXML($child);
$node = $DOMChild->documentElement;
$DOMParent = new DOMDocument;
$DOMParent->formatOutput = true;
$DOMParent->loadXML($parent);
$node = $DOMParent->importNode($node, true);
if ($tag !== null) {
$tag = $DOMParent->getElementsByTagName($tag)->item(0);
$tag->appendChild($node);
} else {
$DOMParent->documentElement->appendChild($node);
}
return $DOMParent->saveXML();
}
?>
----
Server IP: 92.48.74.199
Probable Submitter: 217.158.106.15
----
Manual Page -- http://www.php.net/manual/en/domdocument.importnode.php
Edit -- https://master.php.net/note/edit/87812
Del: integrated -- https://master.php.net/note/delete/87812/integrated
Del: useless -- https://master.php.net/note/delete/87812/useless
Del: bad code -- https://master.php.net/note/delete/87812/bad+code
Del: spam -- https://master.php.net/note/delete/87812/spam
Del: non-english -- https://master.php.net/note/delete/87812/non-english
Del: in docs -- https://master.php.net/note/delete/87812/in+docs
Del: other reasons-- https://master.php.net/note/delete/87812
Reject -- https://master.php.net/note/reject/87812
Search -- https://master.php.net/manage/user-notes.php