我正在使用SimpleXML。我想獲得這個節點的文本屬性。解析XML(PHP)
<yweather:condition text="Mostly Cloudy" ......
我使用這個它不工作:
$xml->children("yweather", TRUE)->condition->attributes()->text;
我正在使用SimpleXML。我想獲得這個節點的文本屬性。解析XML(PHP)
<yweather:condition text="Mostly Cloudy" ......
我使用這個它不工作:
$xml->children("yweather", TRUE)->condition->attributes()->text;
它看起來像您嘗試訪問的屬性,它存儲在陣列中的$ XML-> yweather->屬性()這樣:
$attributes = $xml->condition->attributes();
$weather = $attributes['text'];
爲了應對命名空間,則需要使用children()來獲取該名稱空間的成員。
$weather_items = $xml->channel->item->children("http://xml.weather.yahoo.com/ns/rss/1.0");
這可能有助於提及您所顯示的字符串是Feed的一部分,特別是RSS格式的Yahoo Weather Feed。
在$ xml上執行print_r()以查看結構的外觀。從那裏你應該能夠看到如何訪問信息。
'SimpleXMLElement Object()'。另外編輯問題請再看一遍 – Eray 2011-03-01 14:44:03
可能重複的[PHP命名空間simplexml問題](http://stackoverflow.com/questions/2098170/php-namespace-simplexml-problems) – Gordon 2011-03-01 14:29:39
使用DOM時的確切重複:http://stackoverflow.com/questions/ 3268976/how-to-get-the-tag-yweathercondition-from-yahoo-weather-rss-in-php – Gordon 2011-03-01 14:45:22
你的「不工作」代碼不工作,因爲你做錯了:''是你嘗試rss/condition時rss/channel/item的孩子。 –
Gordon
2011-03-01 15:20:22