note 73830 added to function.simplexml-element-addChild
| From: | l dot j dot peters at student dot utwente dot nl | Date: | Mon, 12 Mar 2007 13:49:47 +0000 |
| Subject: | note 73830 added to function.simplexml-element-addChild | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-124374@lists.php.net to get a copy of this message | ||
Rob Richards and I have come up with a very easy way to append one SimpleXML tree to another:
<?php
function simplexml_append(SimpleXMLElement $parent, SimpleXMLElement $new_child){
$node1 = dom_import_simplexml($parent);
$dom_sxe = dom_import_simplexml($new_child);
$node2 = $node1->ownerDocument->importNode($dom_sxe, true);
$node1->appendChild($node2);
}
?>
And adding a textnode is also easy:
<?php
//$sxe1 (refers to SimpleXMLElement)
$node1 = dom_import_simplexml($sxe1);
$node1->appendChild(new DOMText("my text"));
?>
Ofcourse, you could use this to extend the SimpleXMLElement class and overwrite and improve the
existing addChild function.
Have fun, Luuk Peters.
----
Server IP: 194.109.193.76
Probable Submitter: 130.89.138.208
----
Manual Page -- http://www.php.net/manual/en/function.simplexml-element-addChild.php
Edit -- https://master.php.net/note/edit/73830
Del: integrated -- https://master.php.net/note/delete/73830/integrated
Del: useless -- https://master.php.net/note/delete/73830/useless
Del: bad code -- https://master.php.net/note/delete/73830/bad+code
Del: spam -- https://master.php.net/note/delete/73830/spam
Del: non-english -- https://master.php.net/note/delete/73830/non-english
Del: in docs -- https://master.php.net/note/delete/73830/in+docs
Del: other reasons-- https://master.php.net/note/delete/73830
Reject -- https://master.php.net/note/reject/73830
Search -- https://master.php.net/manage/user-notes.php