title: display data from XML using php simplexml
body: <p>I have a piece of XML which is as follows</p>
  
  <pre><code>&lt;records count="2"&gt;
    &lt;record&gt;
      &lt;firstname&gt;firstname&lt;/firstname&gt;
      &lt;middlename&gt;middlename&lt;/middlename&gt;
      &lt;lastname&gt;lastname&lt;/lastname&gt;
      &lt;namesuffix/&gt;
      &lt;address&gt;
        &lt;street-number&gt;demo&lt;/street-number&gt;
        &lt;street-pre-direction/&gt;
        &lt;street-name&gt;demo&lt;/street-name&gt;
        &lt;street-post-direction/&gt;
        &lt;street-suffix&gt;demo&lt;/street-suffix&gt;
        &lt;city&gt;demo&lt;/city&gt;
        &lt;state&gt;NY&lt;/state&gt;
        &lt;zip&gt;demo&lt;/zip&gt;
        &lt;zip4&gt;demo&lt;/zip4&gt;
        &lt;county&gt;demo&lt;/county&gt;
      &lt;/address&gt;
      &lt;phonenumberdetails&gt;
        &lt;phonenumber&gt;demo&lt;/phonenumber&gt;
        &lt;listed&gt;demo&lt;/listed&gt;
        &lt;firstname&gt;demo&lt;/firstname&gt;
      &lt;/phonenumberdetails&gt;
      &lt;dob day="" month="" year=""/&gt;
      &lt;age/&gt;
      &lt;date-first month="10" year="1999"/&gt;
      &lt;date-last month="04" year="2011"/&gt;
    &lt;/record&gt;
    &lt;record&gt;
      &lt;firstname&gt;firstname&lt;/firstname&gt;
      &lt;middlename&gt;middlename&lt;/middlename&gt;
      &lt;lastname&gt;lastname&lt;/lastname&gt;
      &lt;namesuffix/&gt;
      &lt;address&gt;
        &lt;street-number&gt;demo&lt;/street-number&gt;
        &lt;street-pre-direction/&gt;
        &lt;street-name&gt;demo&lt;/street-name&gt;
        &lt;street-post-direction/&gt;
        &lt;street-suffix&gt;demo&lt;/street-suffix&gt;
        &lt;city&gt;demo&lt;/city&gt;
        &lt;state&gt;NY&lt;/state&gt;
        &lt;zip&gt;demo&lt;/zip&gt;
        &lt;zip4&gt;demo&lt;/zip4&gt;
        &lt;county&gt;demo&lt;/county&gt;
      &lt;/address&gt;
      &lt;phonenumberdetails&gt;
        &lt;phonenumber&gt;demo&lt;/phonenumber&gt;
        &lt;listed&gt;demo&lt;/listed&gt;
        &lt;firstname&gt;demo&lt;/firstname&gt;
      &lt;/phonenumberdetails&gt;
      &lt;dob day="" month="" year=""/&gt;
      &lt;age/&gt;
      &lt;date-first month="10" year="1999"/&gt;
      &lt;date-last month="04" year="2011"/&gt;
    &lt;/record&gt;
  &lt;/records&gt;
  </code></pre>
  
  <p>Now, I have been able to get all the data in PHP using SimpleXML except for the date-first and date-last elements. I have been using code listed below </p>
  
  <pre><code>$dateFirst           = 'date-first';
  $dateLast            = 'date-last';
  $streetNumber        = 'street-number';
  $streetPreDirection  = 'street-pre-direction';
  $streetName          = 'street-name';
  $streetPostDirection = 'street-post-direction';
  $streetSuffix        = 'street-suffix';
  $unitDesignation     = 'unit-designation';
  $unitNumber          = 'unit-number';
  
  foreach ($reportDataXmlrecords-&gt;records-&gt;record as $currentRecord) {
      echo $currentRecord-&gt;$dateFirst['month'].'/'.$currentRecord-&gt;$dateFirst['year'];
      echo $currentRecord-&gt;$dateLast['month'].'/'.$currentRecord-&gt;$dateLast['year'];
      echo $currentRecord-&gt;address-&gt;$streetNumber;
      $currentRecord-&gt;address-&gt;$streetName; // ......and so on 
  }
  </code></pre>
  
  <p>where <code>$reportDataXmlrecords</code> is the part of the simpleXML object from the parent node of  </p>
  
  <p>But the first two echo's don't print anything and all the other are printing correctly, specifically, I cant access the data in</p>
  
  <pre><code>&lt;date-first month="10" year="1999"/&gt;
  &lt;date-last month="04" year="2011"/&gt;
  </code></pre>
  
  <p>Also for debugging if I do</p>
  
  <pre><code>print_r($currentRecord-&gt;$dateFirst);
  </code></pre>
  
  <p>it prints </p>
  
  <pre><code>SimpleXMLElement Object ( 
      [@attributes] =&gt; Array ( [month] =&gt; 10 [year] =&gt; 1999 ) 
  )
  </code></pre>
  
  <p>Any help would be greatly appreciated. Thank you.</p>