【发布时间】:2012-05-19 05:47:39
【问题描述】:
我正在阅读的 XML 如下所示:
<show id="8511">
<name>The Big Bang Theory</name>
<link>http://www.tvrage.com/The_Big_Bang_Theory</link>
<started>2007-09-24</started>
<country>USA</country>
<latestepisode>
<number>05x23</number>
<title>The Launch Acceleration</title>
</latestepisode>
</show>
要获得(例如)最新剧集的编号,我会这样做:
$ep = $xml->latestepisode[0]->number;
这很好用。但是我该怎么做才能从<show id="8511"> 获取 ID?
我尝试过类似的方法:
$id = $xml->show;
$id = $xml->show[0];
但没有任何效果。
更新
我的代码sn-p:
$url = "http://services.tvrage.com/feeds/episodeinfo.php?show=".$showName;
$result = file_get_contents($url);
$xml = new SimpleXMLElement($result);
//still doesnt work
$id = $xml->show->attributes()->id;
$ep = $xml->latestepisode[0]->number;
echo ($id);
奥利。 XML:
http://services.tvrage.com/feeds/episodeinfo.php?show=The.Big.Bang.Theory
【问题讨论】:
-
Accessing @attribute from SimpleXML 的可能副本 - 供参考。