title: Loop through an XML object with SimpleXML
body: <p>I am trying to use SimpleXML in PHP to loop through a XML object - the object format is below:-</p>
  
  <p>I get the following error when I try to get the element tags by name - can anyone explain what I am doing wrong?</p>
  
  <pre><code>Call to undefined method SimpleXMLElement::getElementsByTagName() on ...
  </code></pre>
  
  <p>Below is the XML file I am reading from:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;response&gt;
      &lt;products&gt;
          &lt;item&gt;
              &lt;product_id&gt;32417&lt;/product_id&gt;
              &lt;manufacturer&gt;Alcatel&lt;/manufacturer&gt;
              &lt;model&gt;Sparq 2&lt;/model&gt;
              &lt;deeplink&gt;http://www.mysite.com/sc_offer?gid=32417&lt;/deeplink&gt;
              &lt;thumbnail_URL&gt;http://www.mysite.com/images/devices/thumbs/Alcatel-Sparq-II.jpg&lt;/thumbnail_URL&gt;
              &lt;image_URL&gt;http://www.mysite.com/images/devices/Alcatel-Sparq-II.jpg&lt;/image_URL&gt;
              &lt;price_not_working&gt;0.00&lt;/price_not_working&gt;
              &lt;price_poor&gt;0.00&lt;/price_poor&gt;
              &lt;price_fair&gt;20.00&lt;/price_fair&gt;
              &lt;price_good&gt;25.00&lt;/price_good&gt;
              &lt;price_perfect&gt;25.00&lt;/price_perfect&gt;
              &lt;price_new&gt;25.00&lt;/price_new&gt;
              &lt;battery_new&gt;1.00&lt;/battery_new&gt;
              &lt;battery_perfect&gt;1.00&lt;/battery_perfect&gt;
              &lt;battery_good&gt;1.00&lt;/battery_good&gt;
              &lt;battery_fair&gt;1.00&lt;/battery_fair&gt;
              &lt;battery_poor&gt;0.00&lt;/battery_poor&gt;
              &lt;charger_new&gt;1.00&lt;/charger_new&gt;
              &lt;charger_perfect&gt;1.00&lt;/charger_perfect&gt;
              &lt;charger_good&gt;1.00&lt;/charger_good&gt;
              &lt;charger_fair&gt;1.00&lt;/charger_fair&gt;
              &lt;charger_poor&gt;0.00&lt;/charger_poor&gt;
              &lt;packaging_new&gt;1.00&lt;/packaging_new&gt;
              &lt;packaging_perfect&gt;1.00&lt;/packaging_perfect&gt;
              &lt;packaging_good&gt;1.00&lt;/packaging_good&gt;
              &lt;packaging_fair&gt;1.00&lt;/packaging_fair&gt;
              &lt;packaging_poor&gt;0.00&lt;/packaging_poor&gt;
          &lt;/item&gt;
          &lt;item&gt;
              &lt;product_id&gt;31303&lt;/product_id&gt;
              &lt;manufacturer&gt;Apple&lt;/manufacturer&gt;
              &lt;model&gt;iPhone 3G 8gb&lt;/model&gt;
              &lt;deeplink&gt;http://www.mysite.com/sc_offer?gid=31303&lt;/deeplink&gt;
              &lt;thumbnail_URL&gt;http://www.mysite.com/images/devices/thumbs/iPhone 8 3G.jpg&lt;/thumbnail_URL&gt;
              &lt;image_URL&gt;http://www.mysite.com/images/devices/iPhone 8 3G.jpg&lt;/image_URL&gt;
              &lt;price_not_working&gt;0.00&lt;/price_not_working&gt;
              &lt;price_poor&gt;0.00&lt;/price_poor&gt;
              &lt;price_fair&gt;7.00&lt;/price_fair&gt;
              &lt;price_good&gt;2.00&lt;/price_good&gt;
              &lt;price_perfect&gt;2.00&lt;/price_perfect&gt;
              &lt;price_new&gt;2.00&lt;/price_new&gt;
              &lt;battery_new&gt;1.00&lt;/battery_new&gt;
              &lt;battery_perfect&gt;1.00&lt;/battery_perfect&gt;
              &lt;battery_good&gt;1.00&lt;/battery_good&gt;
              &lt;battery_fair&gt;1.00&lt;/battery_fair&gt;
              &lt;battery_poor&gt;0.00&lt;/battery_poor&gt;
              &lt;charger_new&gt;1.00&lt;/charger_new&gt;
              &lt;charger_perfect&gt;1.00&lt;/charger_perfect&gt;
              &lt;charger_good&gt;1.00&lt;/charger_good&gt;
              &lt;charger_fair&gt;1.00&lt;/charger_fair&gt;
              &lt;charger_poor&gt;0.00&lt;/charger_poor&gt;
              &lt;packaging_new&gt;1.00&lt;/packaging_new&gt;
              &lt;packaging_perfect&gt;1.00&lt;/packaging_perfect&gt;
              &lt;packaging_good&gt;1.00&lt;/packaging_good&gt;
              &lt;packaging_fair&gt;1.00&lt;/packaging_fair&gt;
              &lt;packaging_poor&gt;0.00&lt;/packaging_poor&gt;
          &lt;/item&gt;
      &lt;/products&gt;
  &lt;/response&gt;
  </code></pre>
  
  <p>My PHP code is below:</p>
  
  <pre><code>$devices = $xml-&gt;getElementsByTagName( "response" ); // error on this line
  </code></pre>
  
  <p>I am trying to make devices an array so I can use the data in a foreach loop.</p>