【问题标题】:getAttribute('label') from RSS Feed来自 RSS 源的 getAttribute('label')
【发布时间】:2014-02-24 23:21:24
【问题描述】:

我想从此 rss 提要中获取类别标签,但无法完成。其他一切都完美无缺。

RSS 源代码:

<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 循环中添加一行。我认为解决方案非常简单,但是经过数小时的尝试和搜索后我无法得到它:(

【问题讨论】:

  • 我想过这样的事情,但不幸的是它不起作用: $category = htmlspecialchars($node->getElementsByTagName('category')->item(0)->getAttribute('label') ->nodeValue);

标签: php attributes rss getattribute


【解决方案1】:

解决了!

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-02-21
    • 2017-06-25
    • 2020-07-01
    • 1970-01-01
    • 2010-09-05
    • 2012-08-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多