php simplexml 在读取名称中包含“列 - :"的属性时出现问题 [英] php simplexml issue in reading an attribute that has a 'column - : ' in its name

查看:14
本文介绍了php simplexml 在读取名称中包含“列 - :"的属性时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试读取一个包含:"的 xml 属性,但我遇到了问题......特别是yweather:condition"

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

这是我的代码:

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

我在 stackoverflow 上阅读了另一个线程后到达这里,但结果与我预期的不一样,我得到以下信息:

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

对象(SimpleXMLElement)[3]

object(SimpleXMLElement)[3]

您可以查看上面的链接以查看完整的 xml,

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

我想读取yweather:condition"中的属性我知道如何访问和读取 XML 的其他部分,但是这个部分很棘手……我也尝试过 getAttributes() 但它没有用

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

谢谢

推荐答案

$docMetaAttributes = $docMeta->attributes(); 

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

用于 yweather 命名空间中的命名空间属性

for namespaced attributes in the yweather namespace

http://www.php.net/manual/en/simplexmlelement.属性.php

这篇关于php simplexml 在读取名称中包含“列 - :"的属性时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆