我有一個exrate.xml這個樣子的php讀取@attributes的xml文件循環?
<!--For reference only. Only one request every 5 minutes!-->
<ExrateList>
<DateTime>5/29/2011 8:54:12 PM</DateTime>
<Exrate CurrencyCode="AUD" CurrencyName="AUST.DOLLAR" Buy="21688.77" Transfer="21819.69" Sell="22201.6"/>
<Source>source name </Source>
</ExrateList>
任何人都知道我可以讀取XML和輸出數據。
貨幣|購買|銷售
我使用
<?php
= simplexml_load_file("Service/Forex_Content.xml");
echo '<pre>';
print_r($xml);
echo '</pre>';
?>
SimpleXMLElement Object
(
[DateTime] => 5/29/2011 8:54:12 PM
[Exrate] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[CurrencyCode] => AUD
[CurrencyName] => AUST.DOLLAR
[Buy] => 21688.77
[Transfer] => 21819.69
[Sell] => 22201.6
)
)
我如何循環@屬性顯示的數據?
foreach ($xml as $value){
foreach ($value->@attributes as $key=>$val){ // I have problem here @attributes
}
}
試着解釋一下代碼。初始代碼中有什麼不正確的? – AntonNiklasson 2012-10-28 07:56:07