Parsing data from XML file with multiple of same name attributes in PHP

netelbcn

New Member
I am trying to parse data from the XML below (I shortened the data a lot to give an example of what the data looks like).For each attribute, I would need to store the data in a separate array. XML File\[code\]<report> <title>Resolution Times (Jun 07 00:21)</title> <sets> <set> <legend>Solved in Less than 2 Hours</legend> <values> <value data="http://stackoverflow.com/questions/10928036/8702" date="2012-05-24"/> <value data="http://stackoverflow.com/questions/10928036/8741" date="2012-05-25"/> <value data="http://stackoverflow.com/questions/10928036/8741" date="2012-05-26"/> <value data="http://stackoverflow.com/questions/10928036/8741" date="2012-05-27"/> </values> </set> <set> <legend>Solved in Less than 24 Hours</legend> <values> <value data="http://stackoverflow.com/questions/10928036/36990" date="2012-05-24"/> <value data="http://stackoverflow.com/questions/10928036/37094" date="2012-05-25"/> <value data="http://stackoverflow.com/questions/10928036/37096" date="2012-05-26"/> <value data="http://stackoverflow.com/questions/10928036/37144" date="2012-05-27"/> </values> </set> </sets></report>\[/code\]Below is some test code I am doing to try and read in the data. For testing purposes I am just printing out to see what data is actually pulled.\[code\]$verifyReport = new SimpleXMLElement('305262.xml', null, true);$testing = $verifyReport->sets->set->values->value;echo '<ol>';foreach($testing as $data){ echo '<li>', $data['data'].PHP_EOL; echo '</li>';}echo '</ol>';$testing1 = $verifyReport->sets->sets->values->value;echo '<ol>';foreach($testing1 as $data2){ echo '<li>', $data2['data'].PHP_EOL; echo '</li>';}echo '</ol>';\[/code\]Below is out the output of the data\[code\]1. 87022. 87413. 87414. 8741Warning: Invalid argument supplied for foreach() in /Applications/XAMPP/xamppfiles/htdocs/tango/test.php on line 23\[/code\]I am able to pull in the first set (Solved in Less than 2 hours) ok, but when I try to pull the data from the second set (Solved in Less than 24 Hours), I get the above error.Can anyone help correct this issue?
 
Back
Top