class tagparse
{
private $data;
public $vals;
function tagparse($DATA, $WHITE=1)
{
$index = array();
$this->data = trim($DATA);
$this->data = str_replace(" ", "[tagparse::space]", $this->data); // fix for
$this->data = preg_replace("/(<(\w+).*?>)(<\/\\2>)/", "\\1[tagparse::empty]\\3", $this->data); // fix for empty tags that do not use ommittag
$this->vals = array();
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, $WHITE);
if ( !xml_parse_into_struct($parser, $this->data, $this->vals, $index) )
die("XML error: ".xml_error_string(xml_get_error_code($parser))." at line ".xml_get_current_line_number($parser));
xml_parser_free($parser);
/*
* The code below is all for using of and empty tags that do not use ommittag
*/
$this->data = str_replace("[tagparse::space]", " ", $this->data);
$this->data = str_replace("[tagparse::empty]", "", $this->data);
for($i = 0;$i<count($this->vals);$i++)
{
if(isset($this->vals[$i]['value']))
{
if(strstr($this->vals[$i]['value'], "[tagparse::space]") !== false)
$this->vals[$i]['value'] = str_replace ("[tagparse::space]", " ", $this->vals[$i]['value']);
if(strstr($this->vals[$i]['value'], "[tagparse::empty]") !== false)
$this->vals[$i]['value'] = str_replace ("[tagparse::empty]", "", $this->vals[$i]['value']);
}
}
}
}
this class will grab all of the data and put it into an array for you to access the array of values use
$test = new tagParse($xml);
print_r($test->vals); // this will display the array if you just want to do stuff with it use $test->vals
just a quick not to load in the file as a string use file_get_contents('filename');
the attributes etc are all there and available so just have a play