note 50953 added to function.xml-parse
| From: | alex dot garcia at noos dot fr | Date: | Mon, 14 Mar 2005 21:47:52 +0000 |
| Subject: | note 50953 added to function.xml-parse | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-86438@lists.php.net to get a copy of this message | ||
Here is the inverse function which takes parsed xml array in entry and outputs xml string
enjoy !
function getXmlFromArray($root){
if(count($root) > 0){
$curr_name = $root['name'];
$attribs = $root['attrs'];
$curr_childs = $root['children'];
$curr_data = $root['cdata'];
$xml .= '<'.$curr_name;
if(count($attribs) > 0){
$i = 1;
foreach($attribs as $key => $value){
$curr_attribs .= $key.'="'.$value.'"';
$i++;
if($i <= count($attribs)){
$curr_attribs .= ' ';
}
}
$xml .= ' '.$curr_attribs;
}
if($curr_data != ''){
$xml .=
'><![CDATA['.$curr_data.']]></'.$curr_name.'>';
} else {
if(count($curr_childs) > 0){
$xml .= '>';
foreach($curr_childs as $child){
$xml .= getXmlFromArray($child);
}
$xml .= '</'.$curr_name.'>';
} else {
$xml .= '/>';
}
}
}
return $xml;
}
----
Manual Page -- http://www.php.net/manual/en/function.xml-parse.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50953
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50953&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50953&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50953&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50953&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50953&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50953&report=yes
Search -- http://master.php.net/manage/user-notes.php