2012-01-18 64 views
0

我一直在嘗試閱讀其中包含「:」的xml屬性,但我遇到了麻煩......特別是「 yweather:條件」php simplexml在閱讀名稱中有'column - :'的屬性時的問題

這是我的代碼:

if ($xml = simplexml_load_file("http://weather.yahooapis.com/forecastrss?p=LEXX0003&u=c")) { 
    $namespacesMeta = $xml->getNamespaces(true); 
    $yweather = $xml->children($namespacesMeta['yweather']); 
    $docMeta = $yweather->{'condition'}; 
    var_dump($docMeta); 
} 

我來到這裏讀關上計算器紛紛跟帖,但結果並不如我所料,我得到如下:

對象(SimpleXMLElement)[3]

您可以檢查上面的鏈接查看完整的XML,

我想讀的屬性「yweather:條件」 我知道如何訪問和讀取XML的其他部分,但這個正在棘手的......我也試過的getAttributes()並沒有

感謝

回答

0
$docMetaAttributes = $docMeta->attributes(); 

$docMetaAttributes = $docMeta->attributes($namespacesMeta['yweather']); 

工作在yweather命名空間的命名空間屬性

http://www.php.net/manual/en/simplexmlelement.attributes.php

+0

感謝, 但我已經試過了,我得到了以下錯誤: 警告:的var_dump()[function.var突降]:節點不再存在 – 2012-01-18 16:47:42