我想要track-id即列出的href属性。XML解析/获得标题中的href属性
这是Spotify的xml文件:
http://ws.spotify.com/search/1/track?q=Sportfreunde+Stiller+AND+track:Ein+Kompliment
这是我试过到目前为止:
$url = "http://ws.spotify.com/search/1/track?q=Sportfreunde+Stiller+AND+track:Ein+Kompliment";
$xml = simplexml_load_file($url);
foreach ($xml->track as $track) {
echo $track->name."<br>";
}
如何上层级得到什么?
这是所需的输出:spotify:track:3ptJBraFGtaeprD4BHmTfV
。在我的代码中,我只是将轨道的名称放在输出中,以便您可以看到我处于错误的层次结构中。
较高层级你的意思遍历深入文档树?检查[simplexml用法示例](http://php.net/simplexml.examples-basic),他们证明了这一点,并与示例。 – 2013-04-30 13:05:45
[PHP SimpleXML +获取属性]的可能重复(http://stackoverflow.com/questions/10537657/php-simplexml-get-attribute) – hakre 2013-05-02 12:54:56