Helix Installation   Getting Started   Reference Documentation   Global Functions   Quick Start
ModulesClassesFunctions
 

Class Reference

class xml

Helixxml
Hide Inherited MembersHelix Core
Description
No description.
 
Constants
No constants.
 
Properties
 
Methods
public staticxml2array ( raw_xml )[ xml ]
Parameters
requiredraw_xml
Code
006  public static function xml2array($raw_xml)
007  {
008     $xml_parser = xml_parser_create();
009     xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0);
010     xml_parser_set_option($xml_parser, XML_OPTION_SKIP_WHITE, 1);
011     xml_parse_into_struct($xml_parser, $raw_xml, $vals);
012     xml_parser_free($xml_parser);
013 
014     $_tmp='';
015     foreach ($vals as $xml_elem) {
016        $x_tag=$xml_elem['tag'];
017        $x_level=$xml_elem['level'];
018        $x_type=$xml_elem['type'];
019        if ($x_level!=1 && $x_type == 'close') {
020           if (isset($multi_key[$x_tag][$x_level])) $multi_key[$x_tag][$x_level]=1;
021           else                                     $multi_key[$x_tag][$x_level]=0;
022        }
023        if ($x_level!=1 && $x_type == 'complete') {
024           if ($_tmp==$x_tag)                       $multi_key[$x_tag][$x_level]=1;
025           $_tmp=$x_tag;
026        }
027     }
028 
029     foreach ($vals as $xml_elem) {
030        $x_tag=$xml_elem['tag'];
031        $x_level=$xml_elem['level'];
032        $x_type=$xml_elem['type'];
033        if ($x_type == 'open')               $level[$x_level] = $x_tag;
034        $start_level = 1;
035        $php_stmt = '$xml_array';
036        if ($x_type=='close' && $x_level!=1) $multi_key[$x_tag][$x_level]++;
037        while($start_level < $x_level) {
038           $php_stmt .= '[$level['.$start_level.']]';
039           if (isset($multi_key[$level[$start_level]][$start_level]) && $multi_key[$level[$start_level]][$start_level]) {
040              $php_stmt .= '['.($multi_key[$level[$start_level]][$start_level]-1).']';
041           }
042           $start_level++;
043        }
044        $add='';
045        if (isset($multi_key[$x_tag][$x_level]) && $multi_key[$x_tag][$x_level] && ($x_type=='open' || $x_type=='complete')) {
046           if   (!isset($multi_key2[$x_tag][$x_level])) $multi_key2[$x_tag][$x_level]=0;
047           else                                         $multi_key2[$x_tag][$x_level]++;
048           $add='['.$multi_key2[$x_tag][$x_level].']';
049        }
050        if (isset($xml_elem['value']) && trim($xml_elem['value'])!='' && !array_key_exists('attributes',$xml_elem)) {
051           if   ($x_type == 'open') $php_stmt_main=$php_stmt.'[$x_type]'.$add.'[\'content\'] = $xml_elem[\'value\'];';
052           else                     $php_stmt_main=$php_stmt.'[$x_tag]'.$add.' = $xml_elem[\'value\'];';
053           eval($php_stmt_main);
054        }
055        if (array_key_exists('attributes',$xml_elem)) {
056           if (isset($xml_elem['value'])) {
057              $php_stmt_main=$php_stmt.'[$x_tag]'.$add.'[\'content\'] = $xml_elem[\'value\'];';
058              eval($php_stmt_main);
059           }
060 
061           foreach ($xml_elem['attributes'] as $key=>$value) {
062              $php_stmt_att=$php_stmt.'[$x_tag]'.$add.'[\'attributes\'][$key] = $value;';
063              eval($php_stmt_att);
064           }
065        }
066     }
067     return $xml_array;
068  }
 
Accessors
Get Helix PHP Framework at SourceForge.net. Fast, secure and Free Open Source software downloads