我想通過一個XML對象使用的SimpleXML在PHP循環XML對象 - 對象格式如下: -遍歷用SimpleXML
我收到以下錯誤,當我試圖通過獲得元素標籤名稱 - 任何人都可以解釋我做錯了什麼?
Call to undefined method SimpleXMLElement::getElementsByTagName() on ...
下面是我從讀取XML文件:
<?xml version="1.0" encoding="utf-8"?>
<response>
<products>
<item>
<product_id>32417</product_id>
<manufacturer>Alcatel</manufacturer>
<model>Sparq 2</model>
<deeplink>http://www.mysite.com/sc_offer?gid=32417</deeplink>
<thumbnail_URL>http://www.mysite.com/images/devices/thumbs/Alcatel-Sparq-II.jpg</thumbnail_URL>
<image_URL>http://www.mysite.com/images/devices/Alcatel-Sparq-II.jpg</image_URL>
<price_not_working>0.00</price_not_working>
<price_poor>0.00</price_poor>
<price_fair>20.00</price_fair>
<price_good>25.00</price_good>
<price_perfect>25.00</price_perfect>
<price_new>25.00</price_new>
<battery_new>1.00</battery_new>
<battery_perfect>1.00</battery_perfect>
<battery_good>1.00</battery_good>
<battery_fair>1.00</battery_fair>
<battery_poor>0.00</battery_poor>
<charger_new>1.00</charger_new>
<charger_perfect>1.00</charger_perfect>
<charger_good>1.00</charger_good>
<charger_fair>1.00</charger_fair>
<charger_poor>0.00</charger_poor>
<packaging_new>1.00</packaging_new>
<packaging_perfect>1.00</packaging_perfect>
<packaging_good>1.00</packaging_good>
<packaging_fair>1.00</packaging_fair>
<packaging_poor>0.00</packaging_poor>
</item>
<item>
<product_id>31303</product_id>
<manufacturer>Apple</manufacturer>
<model>iPhone 3G 8gb</model>
<deeplink>http://www.mysite.com/sc_offer?gid=31303</deeplink>
<thumbnail_URL>http://www.mysite.com/images/devices/thumbs/iPhone 8 3G.jpg</thumbnail_URL>
<image_URL>http://www.mysite.com/images/devices/iPhone 8 3G.jpg</image_URL>
<price_not_working>0.00</price_not_working>
<price_poor>0.00</price_poor>
<price_fair>7.00</price_fair>
<price_good>2.00</price_good>
<price_perfect>2.00</price_perfect>
<price_new>2.00</price_new>
<battery_new>1.00</battery_new>
<battery_perfect>1.00</battery_perfect>
<battery_good>1.00</battery_good>
<battery_fair>1.00</battery_fair>
<battery_poor>0.00</battery_poor>
<charger_new>1.00</charger_new>
<charger_perfect>1.00</charger_perfect>
<charger_good>1.00</charger_good>
<charger_fair>1.00</charger_fair>
<charger_poor>0.00</charger_poor>
<packaging_new>1.00</packaging_new>
<packaging_perfect>1.00</packaging_perfect>
<packaging_good>1.00</packaging_good>
<packaging_fair>1.00</packaging_fair>
<packaging_poor>0.00</packaging_poor>
</item>
</products>
</response>
我的PHP代碼如下:
$devices = $xml->getElementsByTagName("response"); // error on this line
我想使器件陣列,所以我可以使用數據在foreach循環中。
+1爲額外的代碼:) – Zabs