title: Accessing Elements/Attributes From XML Using SimpleXML/PHP
body: <p>Quick question: I'm using PHP's SimpleXML object to parse an XML file. For the life of me, I can't figure out how to access specific elements. My question is what would my PHP look like to access the nodes and the info contained in the "data" attributes? I don't want to iterate through the entire document, I only want specific information from the nodes. I tried the following with no luck:</p>
  
  <p>$xml = simplexml_load_file("myXML.xml");
  echo $xml->weather[0]->forecast_information->city->attributes()->data . "<br />";</p>
  
  <p>Thanks in advance.</p>
  
  <pre><code>&lt;xml_api_reply version="1"&gt;
  
  &lt;weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0"&gt;
  
  &lt;forecast_information&gt;
     &lt;city data="Carlsbad, CA"/&gt;
     &lt;postal_code data="92009"/&gt;
     &lt;latitude_e6 data=""/&gt;
     &lt;longitude_e6 data=""/&gt;
     &lt;forecast_date data="2012-03-29"/&gt;
     &lt;current_date_time data="2012-03-29 11:52:00 +0000"/&gt;
     &lt;unit_system data="US"/&gt;
  &lt;/forecast_information&gt;
  
  &lt;current_conditions&gt;
     &lt;condition data="Partly Cloudy"/&gt;
     &lt;temp_f data="62"/&gt;
     &lt;temp_c data="17"/&gt;
     &lt;humidity data="Humidity: 65%"/&gt;
     &lt;icon data="/ig/images/weather/partly_cloudy.gif"/&gt;
     &lt;wind_condition data="Wind: SW at 4 mph"/&gt;
  &lt;/current_conditions&gt;
  
  
  &lt;/weather&gt;
  
  &lt;/xml_api_reply&gt;
  </code></pre>