Skip to main content
Inspiring
June 10, 2010
Answered

cfloop and cfoutput creates carriage return in RSS Feed

  • June 10, 2010
  • 2 replies
  • 2009 views

I am having problems with validation of a RSS Feed that I am creating using CFXML. I have tried both cfoutput and cfloop and is creating the following:

      <item>
        <title>Events: career panel on Career Options with a Library Technician Certificate</title>
        <link>http://events.lbcc.edu/detail.cfm?eventid=1286</link>
        <description>The Library Department & LAC Career & Job Services Center will host a career panel on Career Options with a Library Technician Certificate. 11:00 a.m. to 1:00 p.m. in Building E - Student Center. </description>
      </item>
                                                         <---------------------- cfloop and cfoutput is Adding carriage return creating a non valid rss feed.
      <item>
        <title>Events: EOPS applications will be available beginning May 3</title>
        <link>http://events.lbcc.edu/detail.cfm?eventid=1273</link>
        <description>Due to increased FAFSA application volume in Financial Aid, EOPS applications will be available beginning May 3.For further questions please call 562-938-4772 (LAC) or 562-938-3097 (PCC).</description>
      </item>

If I use cffeed the xml is working correctly as follows and creates a valid feed:

      <item>
        <title>Events: career panel on Career Options with a Library Technician Certificate</title>
        <link>http://events.lbcc.edu/detail.cfm?eventid=1286</link>
        <description>The Library Department & LAC Career & Job Services Center will host a career panel on Career Options with a Library Technician Certificate. 11:00 a.m. to 1:00 p.m. in Building E - Student Center. </description>
      </item>
      <item>
        <title>Events: EOPS applications will be available beginning May 3</title>
        <link>http://events.lbcc.edu/detail.cfm?eventid=1273</link>
        <description>Due to increased FAFSA application volume in Financial Aid, EOPS applications will be available beginning May 3.For further questions please call 562-938-4772 (LAC) or 562-938-3097 (PCC).</description>
      </item>

Here is my code:

<cfcomponent output="false">
<cffunction name="UpdateRSSFeed" access="remote" returntype="void">
<cfset RSSXMLPath = "e:\websites\www\RSSFeed\">

<!--- Create All News and Events Feed--->
<cfinvoke component="eventsystem" method="listAllNewsEvents" returnvariable="listAllNewsEventsRET">

<cfoutput>
     <cfxml variable="AllNewsEventsFeed">
      <rss xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns##" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
        <channel>
        <title>News and Events RSS Feed</title>
        <link>http://www.lbcc.edu/</link>    
        <cfloop query="listAllNewsEventsRET">      
          <item>
            <title><cfif listAllNewsEventsRET.event_typeID eq 2>News:<cfelse>Events:</cfif> #XMLFormat(listAllNewsEventsRET.Event_Title)#</title>
            <link>#listAllNewsEventsRET.FullLink#</link>
            <description>#XMLFormat(listAllNewsEventsRET.summary)#</description>
          </item>
        </cfloop>
       </channel>
       </rss>
      </cfxml> 
    </cfoutput>
    <!--- Write to file --->
     <cffile
          action="write"
          addnewline="no" charset="us-ascii"
          file="#RSSXMLPath#NewsEvents2.xml"
          output="#ToString(AllNewsEventsFeed)#" fixnewline="no">
</cffunction>
</cfcomponent>

Any suggestions would be appreciated.

Thanks.

Ron

This topic has been closed for replies.
Correct answer ilssac

And there is a carriage return at the end of the <cfloop...> line is there not!

<cfloop query="listAllNewsEventsRET"> <-- this is a carriage return!       
<item>

<cfsetting enablecfoutputonly=true> is not going to do much if you just use one big <cfoutput> around all the code you want to output AND all the white space you do not.  To effectiviely use this one you would need to do something like this.

<cfoutput><channel>
<title>News and Events RSS Feed</title>
<link>http://www.lbcc.edu/</link></cfoutput> <cfloop query="listAllNewsEventsRET">      
<cfoutput><item>
<title><cfif listAllNewsEventsRET.event_typeID eq 2>News:<cfelse>Events:</cfif>#XMLFormat(listAllNewsEventsRET.Event_Title)#</title>
<link>#listAllNewsEventsRET.FullLink#</link>         <description>#XMLFormat(listAllNewsEventsRET.summary)#</description>

</item></cfoutput>
</cfloop>
<cfoutput></channel>
</rss></cfoutput>
</cfxml>

2 replies

Inspiring
June 11, 2010

I am having problems with validation of a RSS Feed that I am creating using CFXML. I have tried both cfoutput and cfloop and is creating the following:

      <item>
        <title>Events: career panel on Career Options with a Library Technician Certificate</title>
        <link>http://events.lbcc.edu/detail.cfm?eventid=1286</link>
        <description>The Library Department & LAC Career & Job Services Center will host a career panel on Career Options with a Library Technician Certificate. 11:00 a.m. to 1:00 p.m. in Building E - Student Center. </description>
      </item>
                                                         <---------------------- cfloop and cfoutput is Adding carriage return creating a non valid rss feed.

Another thing... there is absolutely no problem with having whitespace in an RSS feed like this.  What validation is it failing?

--

Adam

ilssac
Inspiring
June 10, 2010

They don't "create" carraige returns.  They send each and every one that is is in your code if is is between an <cfoutput> opening and </cfoutput> closing tag.  Even the very first one that is right after the <cfoutput> tag itself.

ColdFusion offers many ways to help you control whitespace in your document.  Some of the major features are the <cfsilent></cfsilent> tag, <cfsetting enablecfoutputonly=true> tag, <cfprocessingdirective  suppressWhiteSpace="true"></cfprocessingdirective> tag, etc.

But I suspect that your problem may be as simple as removing the offending line break from your code.  I often start my xml output somehting like this:

<cfoutput><myXmlRoot>

<!---other xml tags follow below--->

RonswebAuthor
Inspiring
June 10, 2010

Ian,

Thanks for the reply.  I already tried <cfsilent></cfsilent> tag, <cfsetting enablecfoutputonly=true> tag, <cfprocessingdirective  suppressWhiteSpace="true"></cfprocessingdirective> to no end.

The white space is where the cfloop tag is.  The code is located above.

Ron

ilssac
ilssacCorrect answer
Inspiring
June 10, 2010

And there is a carriage return at the end of the <cfloop...> line is there not!

<cfloop query="listAllNewsEventsRET"> <-- this is a carriage return!       
<item>

<cfsetting enablecfoutputonly=true> is not going to do much if you just use one big <cfoutput> around all the code you want to output AND all the white space you do not.  To effectiviely use this one you would need to do something like this.

<cfoutput><channel>
<title>News and Events RSS Feed</title>
<link>http://www.lbcc.edu/</link></cfoutput> <cfloop query="listAllNewsEventsRET">      
<cfoutput><item>
<title><cfif listAllNewsEventsRET.event_typeID eq 2>News:<cfelse>Events:</cfif>#XMLFormat(listAllNewsEventsRET.Event_Title)#</title>
<link>#listAllNewsEventsRET.FullLink#</link>         <description>#XMLFormat(listAllNewsEventsRET.summary)#</description>

</item></cfoutput>
</cfloop>
<cfoutput></channel>
</rss></cfoutput>
</cfxml>