简体   繁体   English

标题中的XML解析/获取href属性

[英]XML Parsing / Get href attribute in title

I want the track-id that is listed in the href attribute. 我想要href属性中列出的track-id

This is the spotify xml file: 这是spotify xml文件:

http://ws.spotify.com/search/1/track?q=Sportfreunde+Stiller+AND+track:Ein+Kompliment

This is what I tried so far: 这是我到目前为止尝试过的:

$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>";
}

How to get in the upper hierarchy? 如何进入高层?

This is the desired output: spotify:track:3ptJBraFGtaeprD4BHmTfV . 这是所需的输出: spotify:track:3ptJBraFGtaeprD4BHmTfV In my code I just put the name of the track in the output so that you can see that I am in the wrong hierarchy. 在我的代码中,我只是在输出中放入了轨道的名称,这样您就可以看到我处于错误的层次结构中。

You can use $track->attributes() instead of $track->name, it will output the value in the href attribute. 您可以使用$ track-> attributes()代替$ track-> name,它将在href属性中输出值。

Ex: 例如:

<?php
$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->attributes() . "<br>";
}
?>

do print_r($xml) and give what you get print_r($xml)并给出你得到的

It worked fine for me I got name or result like 对我来说效果很好,我得到了类似的名字或结果

Ein Kompliment
Ein Kompliment - Unplugged
Ein Kompliment - Unplugged
Ein Kompliment
Ein Kompliment
Ein Kompliment - Live aus der Olympiahalle München am 26.05.04
Ein Kompliment - Live aus der Olympiahalle München am 26.05.04
Ein Kompliment
Ein Kompliment (Tribute To Sportfreunde Stiller)
Ein Kompliment (Unplugged Karaoke Version) - Originally Performed By Sportfreunde Stiller
Ein Kompliment - Originally Performed By Sportfreunde Stiller
Ein Kompliment (Tribute To Sportfreunde Stiller)
Ein Kompliment - Originally Performed By Sportfreunde Stiller
Ein Kompliment (Karaoke Version) - Originally Performed By Sportfreunde Stiller
Ein Kompliment (Karaoke Version) - Originally Performed By Sportfreunde Stiller

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM