douchui3933 2014-07-07 09:56
浏览 66
已采纳

XML PHP,过滤掉特定的“类型”

I'm extracting the required nodes from the api easily from the response here : https://musicbrainz.org/ws/2/release-group/fc02b10c-8a09-38d6-b612-22c47794d2c6?inc=releases+media+url-rels

However, i am trying to get the target of relation type discogs from the below with no luck, any help appreciated

<relation-list target-type="url">
    <relation type-id="6578f0e9-1ace-4095-9de8-6e517ddb1ceb" type="wikipedia">
        <target id="cba6f347-45b3-4bd5-8b7f-818fa76a63b2">
            http://en.wikipedia.org/wiki/Insineratehymn
        </target>
    </relation>
    <relation type-id="99e550f3-5ab4-3110-b5b9-fe01d970b126" type="discogs">
        <target id="e9e6e840-ca1a-47fa-b835-47d0d86bcda8">
            http://www.discogs.com/master/316106
       </target>
    </relation>
    <relation type-id="b988d08c-5d86-4a57-9557-c83b399e3580" type="wikidata">
        <target id="f9b00d41-6f25-4174-9c72-ba1c452cfa6d">
            http://www.wikidata.org/wiki/Q1932481
        </target>
    </relation>
</relation-list>
  • 写回答

4条回答 默认 最新

  • doulan8054 2014-07-07 10:53
    关注

    Just made a simple code:

    $xml = simplexml_load_file('https://musicbrainz.org/ws/2/release-group/fc02b10c-8a09-38d6-b612-22c47794d2c6?inc=releases+media+url-rels');
    foreach($xml->{'release-group'}->{'relation-list'}->relation as $relation) {
        if($relation['type'] == 'discogs') {
            $link = $relation->target;
        }
    }
    
    echo $link;
    

    Output:

    http://www.discogs.com/master/316106
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含