Skip to main content
Inspiring
March 17, 2007
Question

Help returning XML description w/ BlogCFC feed pod

  • March 17, 2007
  • 3 replies
  • 327 views
This is the feed.cfm from BlogCFC. Currently it returns the last 5
titles of a blog's XML feed.

In addition to displaying the title I'd also like it to display the
first ten words of the description.

Here's the code:

<cftry>
<cfset theURL =
" http://weblogs.macromedia.com/mxna/xml/rss.cfm?query=byMostRecent&languages=1">
<cfhttp url="#theURL#">
<cfset xml = xmlParse(cfhttp.filecontent)>

<cfset items = xmlSearch(xml, "//*[local-name() = 'item']")>
<cfloop index="x" from="1" to="#min(arrayLen(items),5)#">
<cfset item = items>
<cfoutput>
<a href="#item.link.xmlText#">
#item.title.xmlText#
</a>
<br>
</cfoutput>
</cfloop>

<cfcatch>
<cfoutput>
Feed temporarily down.
</cfoutput>
</cfcatch>
</cftry>
    This topic has been closed for replies.

    3 replies

    BKBK
    Community Expert
    Community Expert
    March 19, 2007
    !

    Inspiring
    March 17, 2007
    BKBK,

    Wow, thank you! Once again, you are a genius. I updated the feed (below)
    for the site I'm developing. It displayed the title and descriptions of
    the three articles posted so far.

    I just uploaded the site's first podcast and it appears along with the
    articles on the home page's feed display ( http://tinyurl.com/2q6v7g).

    The other three entries are in the "Articles" category, while the
    podcast entry's category is "Podcast."

    Do you know how to modify your code to return entries from the
    "Articles" category only?

    BKBK wrote:
    > one way to do it
    >
    >
    >
    > <cfscript>
    > function getFirstNWords(str, n) {
    > var first_n_words="";
    > for (i=1; i LTE n; i=i+1) {
    > first_n_words = first_n_words & " " & listgetAt(str,i," ");
    > }
    > return first_n_words;
    > }
    > </cfscript>
    >
    > <cftry>
    > <cfset theURL =
    > " http://www.platformmagazine.com/blog/rss.cfm?mode=full">
    > <cfhttp url="#theURL#">
    >
    > <cfset xml = xmlParse(cfhttp.filecontent)>
    > <cfset items = xmlSearch(xml, "//*[local-name() = 'item']")>
    > <cfloop index="x" from="1" to="#min(arrayLen(items),5)#">
    > <cfset item = items>
    > <cfoutput>
    > <a href="#item["link"].xmlText#">#item["title"].xmlText#</a><br>
    > Description (first 10 words): #getFirstNWords(item["description"].xmlText,
    > 10)# <br><br>
    > </cfoutput>
    > </cfloop>
    > <cfcatch type="any">
    > <p>Feed temporarily down.</p>
    > </cfcatch>
    > </cftry>
    >
    BKBK
    Community Expert
    Community Expert
    March 18, 2007
    note the improvement in getFirstNWords() and the new xPath

    BKBK
    Community Expert
    Community Expert
    March 17, 2007
    one way to do it