3

我创建了一个 utf8 编码的 RSS 提要,它显示了从数据库中提取的新闻数据。我已将数据库的所有方面都设置为 utf8,并将我放入数据库的文本保存为 utf8,方法是将其粘贴到记事本中并另存为 utf8。因此,当将 RSS 提要呈现给浏览器时,所有内容都应该以 utf8 编码,但是我仍然会收到奇怪的问号字符作为井号:(

这是我的 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> 

有人有什么建议吗?我做了很多研究,但找不到任何答案:(

提前致谢,

克罗米斯

4

5 回答 5

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>

查看 XMLFormat livedoc 页面。

于 2008-12-12T18:57:48.117 回答
1

这对我有用,只需组合成一个 cfcontent 标签并附加 charset=utf-8。 <cfcontent type="text/xml; charset=utf-8" reset="yes" />

于 2012-07-18T21:22:35.250 回答
0

你的转义功能太简单了。您需要先更改&&amp;

如果您使用命名实体(即&pound;),则会导致错误。

于 2008-12-12T12:51:02.883 回答
0

在将每个输入输入数据库时​​对其进行清理,这样可以简化之后此类数据的显示。

于 2008-12-15T09:41:20.343 回答
0

如果您使用的是 Adob​​e ColdFusion 9 或更高版本,请考虑使用带有“escapeChars”属性的 CFFEED 来创建您的 RSS(CF8 也支持 CFFEED,但不支持该属性)。

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

于 2012-07-23T09:28:13.297 回答