1<?php 2/* 3description : Simple Xml object class 4author : Ikuo Obataya 5email : i.obataya[at]gmail.com 6lastupdate : 2013-01-29 7license : GPL 2 (http://www.gnu.org/licenses/gpl.html) 8*/ 9class Xml 10{ 11 var $tag; 12 var $value; 13 var $attributes; 14 var $next; 15 16 function GetXmlObject($xml){ 17 $Parser = xml_parser_create(); 18 xml_parser_set_option($Parser, XML_OPTION_CASE_FOLDING, 0); 19 xml_parser_set_option($Parser, XML_OPTION_SKIP_WHITE, 1); 20 xml_parse_into_struct($Parser, $xml, $Xml_Values); 21 xml_parser_free($Parser); 22 $XmlClass = array(); 23 $LastObj = array(); 24 $NowObj = &$XmlClass; 25 26 foreach($Xml_Values as $Xml_Key => $Xml_Value){ 27 $Index = count($NowObj); 28 if($Xml_Value["type"] == "complete"){ 29 $NowObj[$Index] = new Xml; 30 $NowObj[$Index]->tag = $Xml_Value["tag"]; 31 $NowObj[$Index]->value = $Xml_Value["value"]; 32 $NowObj[$Index]->attributes = $Xml_Value["attributes"]; 33 }elseif($Xml_Value["type"] == "open"){ 34 $NowObj[$Index] = new Xml; 35 $NowObj[$Index]->tag = $Xml_Value["tag"]; 36 $NowObj[$Index]->value = $Xml_Value["value"]; 37 $NowObj[$Index]->attributes = $Xml_Value["attributes"]; 38 $NowObj[$Index]->next = array(); 39 $LastObj[count($LastObj)] = &$NowObj; 40 $NowObj = &$NowObj[$Index]->next; 41 }elseif($Xml_Value["type"] == "close"){ 42 $NowObj = &$LastObj[count($LastObj) - 1]; 43 unset($LastObj[count($LastObj) - 1]); 44 } 45 } 46 return $XmlClass; 47 } 48} 49 50