note 92272 added to ref.simplexml
| From: | Andrezzenarterathotmaildotcom at osu1 dot php dot net | Date: | Fri, 17 Jul 2009 05:56:44 +0000 |
| Subject: | note 92272 added to ref.simplexml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-158394@lists.php.net to get a copy of this message | ||
I just wanna add an additional to
"Append/combine/merge one simplexml to another"
The parent should has attributes too.
<?php
function append_simplexml(&$simplexml_to, &$simplexml_from)
{
static $firstLoop=true;
//Here adding attributes to parent
if( $firstLoop )
{
foreach( $simplexml_from->attributes() as $attr_key => $attr_value )
{
$simplexml_to->addAttribute($attr_key, $attr_value);
}
}
foreach ($simplexml_from->children() as $simplexml_child)
{
$simplexml_temp = $simplexml_to->addChild($simplexml_child->getName(), (string)
$simplexml_child);
foreach ($simplexml_child->attributes() as $attr_key => $attr_value)
{
$simplexml_temp->addAttribute($attr_key, $attr_value);
}
$firstLoop=false;
append_simplexml($simplexml_temp, $simplexml_child);
}
unset( $firstLoop=false );
}
?>
I have aproblem to assign an object into a variable used as an object later, Then i found the code
above, it solve half of my problem. I have it should have the parent name assign too but it didnt.
Any better code?
----
Server IP: 209.41.74.194
Probable Submitter: 125.161.54.220
----
Manual Page -- http://www.php.net/manual/en/ref.simplexml.php
Edit -- https://master.php.net/note/edit/92272
Del: integrated -- https://master.php.net/note/delete/92272/integrated
Del: useless -- https://master.php.net/note/delete/92272/useless
Del: bad code -- https://master.php.net/note/delete/92272/bad+code
Del: spam -- https://master.php.net/note/delete/92272/spam
Del: non-english -- https://master.php.net/note/delete/92272/non-english
Del: in docs -- https://master.php.net/note/delete/92272/in+docs
Del: other reasons-- https://master.php.net/note/delete/92272
Reject -- https://master.php.net/note/reject/92272
Search -- https://master.php.net/manage/user-notes.php