title: I can't get all the data from an xml file with php
body: <p>I can get the data from the xml apart from all the &lt;Item&gt; data. The code below only gets the data for the last one.  I thought the foreach would get it for each of them but it doesn't seem to.</p>
  
  <pre><code>&lt;magic5Out version="2.1.0"&gt;
  &lt;Report customerPK="Survey_2" locationPK="229" userId="2299" template="13600" formDate="2012-04-11T00:00:00" dateTimeStarted="2012-04-11T07:34:04" dateTimeMobileReleased="2012-04-11T07:37:03" currentStatus="5" reportGuid="b174d011-77bb-4882-b87e-a2c60bdf265d"&gt;
      &lt;Results&gt;
          &lt;Item itemPK="SurveyTab_9"&gt;
              &lt;q1 listEntry="1.8m" listEntryId="239107"/&gt;
              &lt;q1Comments text=""/&gt;
              &lt;q2 listEntry="Green" listEntryId="239113"/&gt;
              &lt;q2Comments text=""/&gt;
              &lt;item_comments text="test"/&gt;
          &lt;/Item&gt;
          &lt;Item itemPK="SurveyTab_24"&gt;
              &lt;q1 listEntry="2.2m" listEntryId="239108"/&gt;
              &lt;q1Comments text=""/&gt;
              &lt;q2 listEntry="Silver" listEntryId="239112"/&gt;
              &lt;q2Comments text=""/&gt;
              &lt;item_comments text=""/&gt;
          &lt;/Item&gt;
          &lt;Item itemPK="SurveyTab_10"&gt;
              &lt;q1 listEntry="3.0m" listEntryId="239110"/&gt;
              &lt;q1Comments text=""/&gt;
              &lt;q2 listEntry="White" listEntryId="239111"/&gt;
              &lt;q2Comments text=""/&gt;
              &lt;item_comments text="No feed"/&gt;
          &lt;/Item&gt;
          &lt;Item itemPK="SurveyTab_23"&gt;
              &lt;q1 listEntry="2.2m" listEntryId="239108"/&gt;
              &lt;q1Comments text=""/&gt;
              &lt;q2 listEntry="Green" listEntryId="239113"/&gt;
              &lt;q2Comments text=""/&gt;
              &lt;item_comments text=""/&gt;
          &lt;/Item&gt;
      &lt;surveyorComments0 text="testing"/&gt;
      &lt;surveyorName text="NICK"/&gt;
      &lt;surveyorSig opFile="D:\Sites\WebApp_eden\Output\2100\XMLSurvey\Attachments\1cf582f9-776c-472e-b8ce-877a51fae5e1.png"/&gt;
      &lt;/Results&gt;
  &lt;/Report&gt;
  &lt;/magic5Out&gt;
  </code></pre>
  
  <p>here's the php I'm using:</p>
  
  <pre><code>$xml = simplexml_load_file($xml_file); 
  /* more code here that works OK */
  foreach($xml-&gt;Report-&gt;Results-&gt;Item as $tab) {
      $tab_name = (string) $tab['itemPK'];
      $q1_result =  $tab-&gt;q1['listEntry'];
      $q2_result =  $tab-&gt;q2['listEntry'];  etc.
      $q1_comment =  escape_data($tab-&gt;q1Comments['text']);
      $q2_comment =  escape_data($tab-&gt;q2Comments['text']);
      $item_comment = escape_data($tab-&gt;item_comments['text']);
  }
  </code></pre>