This has been covered alot of places, but I can't find anything that will create the kind of array I want for my xml data.
class XMLEngine {
private $Parser;
private $data = array();
public function parse($file){
$this->Parser = xml_parser_create();
xml_set_object($this->Parser, &$this);
xml_parser_set_option($this->Parser, XML_OPTION_SKIP_WHITE, 1);
xml_parser_set_option($this->Parser, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($this->Parser, "tagStart", "tagEnd");
xml_set_character_data_handler($this->Parser, "tagCData");
xml_parse($this->Parser, $file);
xml_parser_free($this->Parser);
return $this->data;
}
private function tagStart($parser, $tag, $attribs){
}
private function tagEnd($parser, $tag){
}
private function tagCData($parser, $cdata){
}
}
XML.file
<?xml version="1.0" encoding="iso-8859-1"?>
<form>
<table>mySQLTable</table>
<input>
<type>text</type>
<id>email</id>
<class>normal</class>
<text>Sometext</text>
<validation>email</validation>
<ajax>yes</ajax>
<length>24</length>
</input>
</form>
Desired array output
FORM->table->mySQLTable
-------->input->type->text
----------------->id->email
----------------->class->normal
----------------->text->sometext
----------------->validation->email
----------------->ajax->yes
----------------->length->24
Most of the stuff I found on google creates an array for every single tag => value when parsing the XML.
When parsing that XML I want to end up with an array which first contains form, then one that contains table and input and then one array that contains all the tags under input like illustrated above.
Could anyone help me with the start, end and data functions in the above class to create an array like this?
Would be most appreciated.