谷歌财务的Xml解析问题

时间:2013-09-16 18:41:29

标签: php xml

有人可以帮我解析一下google finance xml使用php的简单引用吗?这是xml doc:

http://www.google.com/ig/api?stock=CIEL3&q=BVMF

现在,我有

$xmlUrl = "http://www.google.com/ig/api?stock=CIEL3&q=BVMF";
$xmlStr = file_get_contents($xmlUrl);
$xmlObj = simplexml_load_string($xmlStr);
echo $xmlObj->finance->symbol[0];

如何仅从行

打印57.10
<last data="57.10"/>

感谢。

1 个答案:

答案 0 :(得分:0)

您需要使用attributes()方法来访问对象的属性:

echo $xmlObj->finance->last->attributes()->data;

Demo!