Page 1 of 1

How to parse the <enclosure> tage in RSS feed?

Posted: Tue Jun 09, 2009 1:42 am
by becky-atlanta
I found this code to help me get started in parsing RSS feed and extract the basic information I wanted. However, I have tried and tried and tried to parse the <enclosure> tag to extract the url, length and type but no success. What do you suggest I should add to the code below to get the enclosure information?

Code: Select all

    $doc = new DOMDocument();
    $doc->load('http://davebender.podbean.com/feed/');
    $arrFeeds = array();
    foreach ($doc->getElementsByTagName('item') as $node) {
        $itemRSS = array ( 
            'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
            'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
            'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
            'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue
            );
        array_push($arrFeeds, $itemRSS);
 
I appreciate your help.

Re: How to parse the <enclosure> tage in RSS feed?

Posted: Tue Jun 09, 2009 1:50 am
by RishikeshJha
hi,
use this code in your code:
put this code at the start of the code...

Code: Select all

 
$myArray;
$index=-1;
put this code after your own code...

Code: Select all

$myArray[++$index]['title']=$itemRSS['title'];
        $myArray[$index]['desc']=$itemRSS['desc'];
        $myArray[$index]['link']=$itemRSS['link'];
        $myArray[$index]['date']=$itemRSS['date'];  
 
finally return $myArray

Re: How to parse the <enclosure> tage in RSS feed?

Posted: Wed Jun 10, 2009 6:31 am
by becky-atlanta
I have no problem of getting those variables. But what I want from the feed is the <enclosure> tag which have three elements: url, length and type. I don't know how to extract the enclosure tag. Any idea?

Re: How to parse the <enclosure> tage in RSS feed?

Posted: Wed Jun 10, 2009 7:33 am
by mikemike
Without knowing the strucutre of the XML file...

$node->getElementsByTagName('enclosure')->item(0)->nodeValue; perhaps?

Re: How to parse the <enclosure> tage in RSS feed?

Posted: Wed Jun 10, 2009 9:35 am
by becky-atlanta
I had tried that before I turned to the forum for help. It did not work.

Re: How to parse the <enclosure> tage in RSS feed?

Posted: Wed Jun 10, 2009 11:16 am
by pickle
Maybe use an RSS library like SimplePie?

Re: How to parse the <enclosure> tage in RSS feed?

Posted: Wed Jun 17, 2009 9:29 pm
by becky-atlanta
I really like the script I found. It is all very simple and works great. I wish I knew how to modify it to extract the ENCLOSURE tag.

Thanks for mentioning SimplePie. I am checking it out.

Re: How to parse the <enclosure> tage in RSS feed?

Posted: Thu Jun 25, 2009 7:02 pm
by becky-atlanta
I am just testing the example file from simplepie. It got an error on line 13104 in simplepie.inc.