2008-12-12 38 views
3

我創建了一個utf8編碼的RSS源,它提供從數據庫中提取的新聞數據。我已經將我的數據庫的所有方面設置爲utf8,並通過將其粘貼到記事本中並保存爲utf8,將我放入數據庫的文本保存爲utf8。所以,一切都應該被編碼爲utf8當RSS源呈現給瀏覽器,但我仍然得到了英鎊符號:(如何擺脫RSS提要中的怪異字符?

這裏是我的RSS源代碼(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> 

有沒有人有什麼建議?我做的研究負載,但找不到任何答案:(提前

感謝,

Chromis

回答

0

您的轉義功能太簡單了。您需要先將&更改爲&amp;

如果您使用導致錯誤的命名實體(即&pound;)。

6

擺脫你逃避的代碼和使用XMLFormat代替:

<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 XMLFormat livedoc page.

0

消毒時,在數據庫中輸入每個輸入,這樣,以後應該簡化這種數據的顯示。

1

這對我來說很簡單,只需將它合併成一個cfcontent標籤並附加charset = utf-8即可。 <cfcontent type="text/xml; charset=utf-8" reset="yes" />