1<?php
2/*
3description : Simple Xml object class
4author      : Ikuo Obataya
5email       : i.obataya[at]gmail.com
6lastupdate  : 2023-08-07
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    $TG = "tag";
26    $VL = "value";
27    $AT = "attributes";
28    foreach($Xml_Values as $Xml_Key => $Xml_Value){
29      $Index = count($NowObj);
30      if($Xml_Value["type"] == "complete"){
31        $NowObj[$Index] = new Xml;
32        $NowObj[$Index]->tag = array_key_exists($TG,$Xml_Value)?$Xml_Value[$TG]:"";
33        $NowObj[$Index]->value = array_key_exists($VL,$Xml_Value)?$Xml_Value[$VL]:"";
34        $NowObj[$Index]->attributes = array_key_exists($AT,$Xml_Value)?$Xml_Value[$AT]:"";
35      }elseif($Xml_Value["type"] == "open"){
36        $NowObj[$Index] = new Xml;
37        $NowObj[$Index]->tag = array_key_exists($TG,$Xml_Value)?$Xml_Value[$TG]:"";
38        $NowObj[$Index]->value = array_key_exists($VL,$Xml_Value)?$Xml_Value[$VL]:"";
39        $NowObj[$Index]->attributes = array_key_exists($AT,$Xml_Value)?$Xml_Value[$AT]:"";
40        $NowObj[$Index]->next = array();
41        $LastObj[count($LastObj)] = &$NowObj;
42        $NowObj = &$NowObj[$Index]->next;
43      }elseif($Xml_Value["type"] == "close"){
44        $NowObj = &$LastObj[count($LastObj) - 1];
45        unset($LastObj[count($LastObj) - 1]);
46      }
47    }
48    return $XmlClass;
49  }
50}
51