来自RSS Feed的getAttribute('label')

时间:2014-02-24 23:21:25

标签: php attributes rss getattribute

我想从这个RSS Feed中获取类别标签,但是无法完成它。其他一切都完美无缺。

RSS Feed代码:

<im:name>Quizduell</im:name>
<link rel="alternate" type="text/html" href="https://itunes.apple.com/de/app/quizduell/id643791032?mt=8&uo=2"/>
<im:contentType term="Application" label="Programm"/>
<category im:id="6014" term="Games" scheme="https://itunes.apple.com/de/genre/ios-spiele/id6014?mt=8&uo=2" label="Spiele"/>
<im:artist href="https://itunes.apple.com/de/artist/feo-media/id534160178?mt=8&uo=2">FEO Media</im:artist>
<im:price amount="0.00000" currency="EUR">Gratis</im:price>

我的PHP小部件代码:

    $count = 0;
    foreach ($doc->getElementsByTagName('entry') as $node) {
        $count = $count + 1;
        $title = htmlspecialchars($node->getElementsByTagName('name')->item(0)->nodeValue); 
        $id = ExtractID(utf8_encode($node->getElementsByTagName('id')->item(0)->nodeValue));
        $price  = htmlspecialchars($node->getElementsByTagName('price')->item(0)->nodeValue);
        $sellerName = htmlspecialchars(($node->getElementsByTagName('artist')->item(0)->nodeValue));
        $image = utf8_encode($node->getElementsByTagName('image')->item(0)->nodeValue);
        $afflink = WP_PLUGIN_URL."/".PLUGIN_BASE_DIRECTORY."/AppStore.php?appid=".$id;

        $appList .= '<li class="store">
                <a class="noeffect" href="'.$afflink.'" rel="nofollow" target="_blank">
                <span class="rank">'.$count.'.</span>
                <img class="image" src=\''.$image.'\'></img>
                <span class="comment">'.$sellerName.'</span>
                <span class="name">'.$title.'</span>
                <span class="comment">'.$price.' '.$label.'</span>                  
                </a>
            </li>';
        if ($count==$topCount){
            break;
            }

我尝试添加getAttribute('label'),但我无法让它工作。我想在foreach循环中添加一行。我认为这个解决方案很容易,但是经过几个小时的尝试和搜索网络后我无法得到它:(

1 个答案:

答案 0 :(得分:0)

解决了!

        foreach ($node->getElementsByTagName('category') as $node) {
        $label = $node->getAttribute('label'); 
        }