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


i trying parse data xml below (i shortened data lot give example of data looks like).

for each attribute, need store data in separate array.

xml file

<report>     <title>resolution times (jun 07 00:21)</title>     <sets>         <set>             <legend>solved in less 2 hours</legend>             <values>                 <value data="8702" date="2012-05-24"/>                 <value data="8741" date="2012-05-25"/>                 <value data="8741" date="2012-05-26"/>                 <value data="8741" date="2012-05-27"/>             </values>         </set>         <set>             <legend>solved in less 24 hours</legend>             <values>                 <value data="36990" date="2012-05-24"/>                 <value data="37094" date="2012-05-25"/>                 <value data="37096" date="2012-05-26"/>                 <value data="37144" date="2012-05-27"/>             </values>         </set>     </sets> </report> 

below test code doing try , read in data. testing purposes printing out see data pulled.

$verifyreport = new simplexmlelement('305262.xml', null, true); $testing = $verifyreport->sets->set->values->value;  echo '<ol>'; foreach($testing $data) {     echo '<li>',     $data['data'].php_eol;     echo '</li>'; }  echo '</ol>';  $testing1 = $verifyreport->sets->sets->values->value;  echo '<ol>'; foreach($testing1 $data2) {     echo '<li>',     $data2['data'].php_eol;     echo '</li>'; }  echo '</ol>'; 

below out output of data

1. 8702 2. 8741 3. 8741 4. 8741  warning: invalid argument supplied foreach() in  /applications/xampp/xamppfiles/htdocs/tango/test.php on line 23 

i able pull in first set (solved in less 2 hours) ok, when try pull data second set (solved in less 24 hours), above error.

can correct issue?

in second block have $testing1 = $verifyreport->sets->sets->values->value; guess second sets has set instead. anyway, why don't iterate on $verifyreport->sets , read further values inside of loop?

new simplexmlelement('305262.xml', null, true); foreach ($verifyreport->sets->set $set) {     echo '<ol>';     foreach ($set->values->value $data) {         echo '<li>',         $data['data'] . php_eol;         echo '</li>';     }     echo '</ol>'; } 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -