我正在阅读的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];
但是没有一个有效。
更新
我的代码片段:
$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);
Ori. XML:
http://services.tvrage.com/feeds/episodeinfo.php?show=The.Big.Bang.Theory