note 19035 rejected from function.xml-parse-into-struct by didou
| From: | didou@php.net | Date: | Fri, 03 Oct 2003 10:44:44 +0000 |
| Subject: | note 19035 rejected from function.xml-parse-into-struct by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-57687@lists.php.net to get a copy of this message | ||
Note Submitter: oknapp@soly.de
----
I modified gdemartini@bol.com.br's code a bit to satisfy my needs. I needed a more object
orientated aspect (at least this is in my opinion) and so, a object has a tag, attributes, values
and children. The children itself are objects again. Is the information identified by the
"complete" type.
That's the code:
-----------------------------
class xmltree{
function GetChildren($vals, &$i){
$children = array();
$all = array();
$all[0] = array();
$all[1] = array();
if ($vals[$i]['value']){
array_push($children, $vals[$i]['value']);
}
while (++$i < count($vals)){
switch ($vals[$i]['type']){
case 'cdata':
array_push($children, $vals[$i]['value']);
break;
case 'complete': //values
array_push($all[0], array('tag' => $vals[$i]['tag'],
'attributes' => $vals[$i]['attributes'], 'value' =>
$vals[$i]['value']));
break;
case 'open': //objects
$tmp = $this->GetChildren($vals, $i);
array_push($all[1], array('tag' => $vals[$i]['tag'],
'attributes' => $vals[$i]['attributes'], 'values' => $tmp[0],
'children' => $tmp[1]));
break;
case 'close':
return $all;
}
}
}
function GetXMLTree($vals, $index){
$tree = array();
$i = 0;
$tmp = $this->GetChildren($vals, $i);
array_push($tree,array('tag'=>$vals[$i]['tag'],
'attributes'=>$vals[$i]['attributes'], 'values' => $tmp[0],
'children' => $tmp[1]));
return $tree;
}
}
-------------------------------------
Hope that this may be of help for somebody. If you know how to implement this piece of code a bit
smoother, especially the $tmp array I would be very pleased, if you let me know how....