I love to beat up on the cffeed tag. I mean I'm happy it was added to the language, but out of all the features in CF8, this one seemed to be the most flakey. Just look at the blog entries:
CFFEED and Date Values
Ask a Jedi: Handling RSS feeds with custom data
CFFEED Fixes in 8.0.1
Fun little feed parsing issue to watch out for - new lines!
CFFEED Tip - Structure versus Query
Metadata properties for CFFEED
Bug to watch out for with CFFEED
Columnmap Gotcha for CFFEED
Ok, so not all of those entries are complaining, but CFFEED is still my favorite tag to kick around. I ran into another problem this week with a user submitted question. He was using columnMap with CFFEED and kept getting:
There is a problem in the column mappings specified in the columnMap structure
The cffeed query does not contain any column by the name of CITY.
He was still on CF 8 with the upper case bug, but he was properly using upper case in his structure:
<cfquery name="xmlStateCities" datasource="#request.dsn.name#">
SELECT DISTINCT(city) as city
,SUM(population) AS population
,state
FROM tbl_zip
WHERE stateFullName = 'ALABAMA'
GROUP BY city, state
ORDER BY city ASC;
</cfquery>
<cfset cmap = structNew()>
<cfset cmap.city = "CITY">
<cfset cmap.state = "STATE">
<cfset cmap.population = "POPULATION">
<cfset cmap.siteurl = "SITEURL">
Everything looked right to me and I couldn't figure out why CFFEED was saying the column didn't exist in the query. Turns out it was a simple user error. If you are like me, you probably didn't notice that in his column map structure, he used the same key name and value. Ie:
<cfset cfmap.city = "CITY">
The error was not that that city didn't exist in his source query. The error was that city wasn't a valid value for the RSS query. This is a great example of how an exception message can either help you or send you down the wrong path. (And yes, I'll file a bug report for this!) Here is the exception I would use. (Just writing this off the top of my head so pardon any misspellings/grammar issues etc.)
There is a problem in the column mappings specified in the columnMap structure
You tried to map to a column (CITY) that is not valid for RSS2.0 feeds. Please use one of (LIST HERE).
To be fair, some of the other new features of ColdFusion 8 have extremely well written exceptions. For example, if you try to read in an image and use an invalid file type, the exception message will a) tell you that it's invalid and b) tell you to use getReadableImageFormats. That's sweet.
Archived Comments
I've only just taken a look at CFFEED and adapted some code I found on someone's website. But something's amiss and I'm sure it's just something stupid I've done. Can some CFFEED aficionado help me out here?
Webpage is http://www.bargainz.co.nz/i...
It showing all the text running together with no formatting, links etc. I can see the XML in the source though.
Code is as follows:
<cfset qry_sales = "#request.qry_allSalesByCity#">
<cfset myStruct = StructNew() />
<cfset mystruct.link = "http://www.bargainz.co.nz" />
<cfset myStruct.title = "Sales" />
<cfset mystruct.description = "Sales at Bargainz.co.nz" />
<cfset mystruct.pubDate = Now() />
<cfset mystruct.version = "rss_2.0" />
<cfset myStruct.item = ArrayNew(1) />
<cfloop query="qry_sales">
<cfset myStruct.item[currentRow] = StructNew() />
<cfset myStruct.item[currentRow].guid = structNew() />
<cfset myStruct.item[currentRow].guid.isPermaLink="NO" />
<cfset myStruct.item[currentRow].guid.value = 'http://www.bargainz.co.nz/i... />
<cfset myStruct.item[currentRow].saleDates = #dateFormat(startDate,"dd mm yyy")# - #dateFormat(endDate,"dd mm yyy")# />
<cfset myStruct.item[currentRow].title = xmlFormat(#title#) />
<cfset myStruct.item[currentRow].description = StructNew() />
<cfset myStruct.item[currentRow].description.value = xmlFormat(#description#) />
<cfset myStruct.item[currentRow].link = 'http://www.bargainz.co.nz/i... />
</cfloop>
<!--- Generate the feed and save it to a file and variable. --->
<cffeed action="create" name="#myStruct#" overwrite="true" xmlVar="myXML" />
<cfoutput>#myXML#</cfoutput>
You need your cfcontent tag.
<cfcontent type="text/xml; charset=utf-8" reset="true"><cfoutput>#myXML#</cfoutput>
Hi, I think this still is not fixed in CF10, any alternative to this
To this? By this you mean the issue where you can't map to an invalid RSS key? The bug is just bad error reporting. You don't work around this, you just don't do it. If you are talking about something else, please let me know.
Hi Ray, Yes that seems to be throwing an error, by this does it have some specific set of cfmap values which can be used only, or does it need al columns to be in Upper case
.... eh?