2016-03-31 13 views
0

名前空間を含むRSSフィードの解析に問題があります。私はこのシナリオでPHPを使用しており、他のすべてのファイルは適切に解析されています。RSSフィードの名前空間でタグを解析する方法<site:content>

問題があるのはRSSフィードの説明だけです。このタグは<job:description>です。

アドバイスをいただければ幸いです!

<?php 

    $rss = new DOMDocument(); 
    $rss->load('http://careers.pageuppeople.com/671/cw/en-us/rss'); 
    $feed = array(); 
    foreach ($rss->getElementsByTagName('item') as $node) { 
        $item = array ( 
            'title' => $node->getElementsByTagName('title')->item(0)->nodeValue, 
            'desc' => $node->getElementsByTagNameNS("http://careers.pageuppeople.com/671/cw/en-us/rss","description")->item(0)->nodeValue, 
            'link' => $node->getElementsByTagName('link')->item(0)->nodeValue, 
            'pubDate' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue, 
            'closeDate' => $node->getElementsByTagName('closingDate')->item(0)->nodeValue, 
            'field_city' => $node->getElementsByTagName('location')->item(0)->nodeValue, 
            ); 
        array_push($feed, $item); 
    } 
    $limit = 5; 
    echo '<?xml/>'; 
    for($x=0;$x<$limit;$x++) { 
        echo '<item>'; 
        $title = str_replace(' & ', ' &amp; ', $feed[$x]['title']); 
        $link = $feed[$x]['link']; 
        $description = $feed[$x]['desc']; 
        $field_city = $feed[$x]['field_city']; 
        $pubDate = date('Y: m: d', strtotime($feed[$x]['pubDate'])); 
        $closeDate = date('Y: m: d', strtotime($feed[$x]['closeDate'])); 
        echo '<title>'.$title.'</title>'; 
        echo '<pubDate>'.$pubDate.'</pubDate>'; 
        echo '<closeDate> '.$closeDate.'</closeDate>'; 
        echo '<link>'.$link.'</link>'; 
        echo '<field_city>'.$field_city.'</field_city>'; 
        echo '<body>'.$description.'</body>'; 
        echo '<field_how_to_apply><strong>UNICEF is committed to diversity and inclusion within its workforce, and encourages qualified female and male candidates from all national, religious and ethnic backgrounds, including persons living with disabilities, to apply to become a part of our organization.<br><br>To apply click on the link below.</strong><br><br>'.$link.'</field_how_to_apply>'; 
        echo '</item>'; 

    } 

    echo '</channel></rss>'; 

?> 

答えて

1

不適切なNameSpaceURIを使用しています。ネームスペースノードの親ノード(一般に、ルートノード内)で、xmlns:prefixを検索しているNameSpaceURIを見つけることができます。あなたのケースでは

(...) 
'desc' => $node->getElementsByTagNameNS("http://pageuppeople.com/","description")->item(0)->nodeValue, 
(...) 

とスクリプトウィル作品:

<channel xmlns:job="http://pageuppeople.com/"> 

だから、あなたは正しいてnsURIを使用する必要があります。

+0

魅力的な作品はありがとうございます! – PiotrK

関連する問題