List Info

Thread: note 72750 added to function.simplexml-element-addchild




note 72750 added to function.simplexml-element-addchild
user name
2007-01-31 10:51:08
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.94
Probable Submitter: 145.99.160.156
----
Manual Page -- http://www.php.net/manual/en/function.simple
xml-element-addchild.php
Edit        -- https://master
.php.net/note/edit/72750
Del: integrated  -- h
ttps://master.php.net/note/delete/72750/integrated
Del: useless     -- http
s://master.php.net/note/delete/72750/useless
Del: bad code    -- htt
ps://master.php.net/note/delete/72750/bad+code
Del: spam        -- https:/
/master.php.net/note/delete/72750/spam
Del: non-english -- 
https://master.php.net/note/delete/72750/non-english
Del: in docs     -- http
s://master.php.net/note/delete/72750/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/72750
Reject      -- https://mast
er.php.net/note/reject/72750
Search      -- https://
master.php.net/manage/user-notes.php

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


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )