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条)

报告相同问题?

悬赏问题

  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败