2016-03-31 9 views
0

İsim alanları dahil olmak üzere RSS beslemeyi ayrıştırma konusunda bir sorunum var. Bu senaryo için PHP kullanıyorum ve dosyalanan diğer tüm dosyalar doğru şekilde ayrıştırıldı.RSS beslemesinde ad alanlarına sahip etiketler nasıl ayrılır <site: content>

Sorunlardan yalnızca biri RSS beslemesinde açıklanmaktadır. Bu etiket <job:description>'dur.

Herhangi bir tavsiye çok takdir edilecektir!

<?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>'; 

?> 

cevap

1

Yanlış bir NameSpaceURI kullanıyorsunuz. AdSpaceURIs öğesini, adlandırılmış düğümün (genellikle kök düğümde) bir üst düğümünde xmlns:prefix aramasını bulabilirsiniz. Senin durumunda

:

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

ve komut wil çalışması:

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

Yani doğru NSURI kullanmak zorunda.

+0

Çekicilik gibi çalışır Çok teşekkür ederim! – PiotrK