How to get rid of weird characters in my RSS feed?

I created an utf8 encoded RSS feed that represents news feeds retrieved from the database. I installed all aspects of my database in utf8, and also saved the text that I put into the database as utf8, pasted it into notepad and saved as utf8. This way everything should be encoded in utf8 when the RSS feed is presented to the browser, however I still get strange question mark characters for the pound signs :(

Here is my RSS feed code (CFML):

<cfsilent> <!--- Get News ---> <cfinvoke component="com.news" method="getAll" dsn="#Request.App.dsn#" returnvariable="news" /> </cfsilent> <!--- If we have news items ---> cfif news.RecordCount GT 0> <!--- Serve RSS content-type ---> <cfcontent type="application/rss+xml"> <!--- Output feed ---> <cfcontent reset="true"><?xml version="1.0" encoding="utf-8"?> <cfoutput> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> <channel> <title>News RSS Feed</title> <link>#Application.siteRoot#</link> <description>Welcome to the News RSS Feed</description> <lastBuildDate>Wed, 19 Nov 2008 09:05:00 GMT</lastBuildDate> <language>en-uk</language> <atom:link href="#Application.siteRoot#news/rss/index.cfm" rel="self" type="application/rss+xml" /> <cfloop query="news"> <!--- Make data xml compliant ---> <cfscript> news.headline = replace(news.headline, "<", "&lt;", "ALL"); news.body = replace(news.body, "<", "&lt;", "ALL"); news.date = dateformat(news.date, "ddd, dd mmm yyyy"); news.time = timeformat(news.time, "HH:mm:ss") & " GMT"; </cfscript> <item> <title>#news.headline#</title> <link>#Application.siteRoot#news/index.cfm?id=#news.id#</link> <guid>#Application.siteRoot#news/index.cfm?id=#news.id#</guid> <pubDate>#news.date# #news.time#</pubDate> <description>#news.body#</description> </item> </cfloop> </channel> </rss> </cfoutput> <cfelse> <!--- If we have no news items, relocate to news page ---> <cflocation url="../news/index.cfm" addtoken="no"> </cfif> 

Does anyone have any suggestions? I have done a lot of research, but I can not find the answers :(

Thanks in advance,

Chromis

+3
source share
5 answers

Get rid of your escape code and use XMLFormat instead:

 <item> <title>#XMLFormat(news.headline)#</title> <link>#Application.siteRoot#news/index.cfm?id=#XMLFormat(news.id)#</link> <guid>#Application.siteRoot#news/index.cfm?id=#XMLFormat(news.id)#</guid> <pubDate>#XMLFormat(news.date)# #XMLFormat(news.time)#</pubDate> <description>#XMLFormat(news.body)#</description> </item> 

View the XMLFormat liveoc page.

+6
source

This worked for me by simply combining into a single cfcontent tag and adding charset = utf-8. <cfcontent type="text/xml; charset=utf-8" reset="yes" />

+1
source

Your screening function is too simple. First you need to change & to &amp; .

If you use named objects (i.e. &pound; ) that are causing the error.

0
source

Sanitize every entry when it is entered into the database, thus subsequently simplifying the display of such data.

0
source

If you use Adobe ColdFusion 9 or higher, consider using CFFEED with the "escapeChars" attribute to create your RSS feed (CF8 also supports CFFEED, but not this attribute).

http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7675.html

0
source

All Articles