Nobody wants to help, any way I tried to help myself. This is the solution I found:
class XmlTransformer
{
var $_parser;
var $_file;
var $_object = array();
var $_depth = 0;
var $_values = array();
var $obj;
var $_current;
function XmlTransformer($file)
{
$this->_file = $file;
$this->_parser = xml_parser_create();
}
function parse()
{
if (!($fp = fopen($this->_file, "r"))) {
die("could not open XML input");
}
while ($data = fread($fp, 4096)) {
$content .= $data;
}
xml_parser_set_option($this->_parser,XML_OPTION_CASE_FOLDING,0);
xml_parser_set_option($this->_parser,XML_OPTION_SKIP_WHITE,1);
xml_parse_into_struct($this->_parser,$content,$this->_values);
xml_parser_free($this->_parser);
$this->makeObject();
}
function makeObject(){
$num = count($this->_values);
$levels = array();
$oldlevel = 0;
$this->_current = array();
for($i=0;$i<$num;$i++){
$tag = $this->_values[$i]["tag"];
$type = $this->_values[$i]["type"];
$level = $this->_values[$i]["level"];
$this->constructPath($tag,$level,$oldlevel);
if($type=="complete"){
$value = $this->_values[$i]["value"];
eval("\$this->obj".$this->typeElements()."='".$value."';\n");
}
$oldlevel = $level;
}
}
function typeElements(){
$result = "";
foreach($this->_current as $val){
$result .= "[\"".$val."\"]";
}
return $result;
}
function constructPath($tag,$level,$oldlevel){
if($level > $oldlevel){
array_push($this->_current,$tag);
}else{
$num = ($oldlevel - $level)+1;
for($i=0;$i<$num;$i++){
array_pop ($this->_current);
}
array_push($this->_current,$tag);
}
}
}
$xt = new XmlTransformer("config.xml");
$xt->parse();
print "<pre>";
print_r($xt);
print "</pre>";