php simplexml issue in reading an attribute that has a 'column - : ' in its name

三世轮回 提交于 2019-12-02 21:19:18

问题


I have been trying to read an xml attribute that has a " : " in it, but I'm having trouble...specifically "yweather:condition"

This is my code:

 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);
}

i got here after reading off another thread on stackoverflow, but the result is not as I expected, I get the following:

object(SimpleXMLElement)[3]

You can check the above link to see the full xml,

I want to read the attributes in "yweather:condition" I know how to access and read the other parts of the XML, but this one is being tricky...I also tried getAttributes() and it did not work

thanks


回答1:


$docMetaAttributes = $docMeta->attributes(); 

or

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

for namespaced attributes in the yweather namespace

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



来源:https://stackoverflow.com/questions/8912256/php-simplexml-issue-in-reading-an-attribute-that-has-a-column-in-its-name

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!