Eric,

On Monday, March 29, 2004, 7:13:50 PM, you wrote:

EH> Any quick good pointers to cf-based tag to pull rss feeds?

Here is something that has worked for me. MX is required. I'm not sure
if the method for detecting the feed type is all that great, but so
far so good.

It is set up to accept a list of feed URLs and return a record for
each. Within each 'meta' record is a 'results' cell which contains the
articles retrieved for that URL.

<cffunction name="fetchfeeds" access="public" returntype="any">
<cfargument name="strurls" type="string" required="yes" />
<cfargument name="strdelims" type="string" required="yes" default="," />
<cfset qrymeta=querynew("title,link,desc,source,results")>
<cfloop list="#arguments.strurls#" index="thisurl" delimiters="#arguments.strdelims#">
        <cftry>
                <cfhttp url="" method="get" resolveurl="yes" timeout="10" throwonerror="yes" />
                <cfscript>
                        xmldoc=xmlparse(cfhttp.filecontent);

                        if(xmlchildpos(xmldoc,"rss",1) eq 1){
                                pathtometa="rss.channel";
                                pathtoitems="rss.channel.item";
                        }else{
                                pathtometa="rdf.channel";
                                pathtoitems="rdf.item";
                        }

                        meta=evaluate("xmldoc."&pathtometa);
                        items=evaluate("xmldoc."&pathtoitems);

                        if(structkeyexists(meta[1],"title")){title=meta[1].title.xmltext;}else{title="";}
                        if(structkeyexists(meta[1],"link")){link=meta[1].link.xmltext;}else{link="";}
                        if(structkeyexists(meta[1],"description")){desc=meta[1].description.xmltext;}else{desc="";}
                        queryaddrow(qrymeta);
                        querysetcell(qrymeta,"title",title);
                        querysetcell(qrymeta,"link",link);
                        querysetcell(qrymeta,"desc",desc);
                        querysetcell(qrymeta,"source",thisurl);

                        qryitems=querynew("title,link,desc");   
                        for(i=1;i lte arraylen(items);i=i+1){
                                if(structkeyexists(items[i],"title")){title=items[i].title.xmltext;}else{title="";}
                                if(structkeyexists(items[i],"link")){link=items[i].link.xmltext;}else{link="";}
                                if(structkeyexists(items[i],"description")){desc=items[i].description.xmltext;}else{desc="";}   
                                queryaddrow(qryitems);         
                                querysetcell(qryitems,"title",title);                  
                                querysetcell(qryitems,"link",link);
                                querysetcell(qryitems,"desc",desc);
                        }
                        querysetcell(qrymeta,"results",qryitems);      
                </cfscript>
                <cfcatch />
        </cftry>
</cfloop>
<cfreturn qrymeta>
</cffunction>

~ Ubqtous ~
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to