问题与CFFEED

时间:2010-07-23 00:33:14

标签: coldfusion cffeed

是的,我正在开发一个有几个不同RSS源的网站。我的问题是我的一个feed工作正常,但第二个(基于几乎相同的代码)失败,我无法弄清楚为什么。

以下是有效的代码:

<!--- Get the feed data as a query from the orders table. ---> 
<cfquery name="getNews" datasource="#DSN#">  
    SELECT * FROM NEWS2
    WHERE STATUS = 1 
    ORDER BY rdate DESC
</cfquery>  


<cfset myStruct = StructNew() />
<cfset mystruct.link = "http://noobzilla.net" />
<cfset myStruct.title = "Noobzilla News" />
<cfset mystruct.description = "Programming Related Site Reviews" />
<cfset mystruct.pubDate = Now() />
<cfset mystruct.version = "rss_2.0" />
<cfset myStruct.item = ArrayNew(1) />

<cfloop query="getNews">
    <cfset myStruct.item[currentRow] = StructNew() />
    <cfset myStruct.item[currentRow].guid = structNew() />
    <cfset myStruct.item[currentRow].guid.isPermaLink="YES" />
    <cfset myStruct.item[currentRow].guid.value = 'http://noobzilla.net/news-detail.cfm?id=#id#' />    
    <cfset myStruct.item[currentRow].pubDate = "#DateFormat(getNews.rdate, "mm/dd/yyyy")#" />
    <!---<cfset myStruct.item[currentRow].title = xmlFormat(title) />--->
    <cfset myStruct.item[currentRow].title = #title# />
    <cfset myStruct.item[currentRow].description = StructNew() />
    <!---<cfset myStruct.item[currentRow].description.value = xmlFormat(#info#) />--->
    <cfset myStruct.item[currentRow].description.value = '#Left(info, 250)#...' />
    <cfset myStruct.item[currentRow].link = 'http://noobzilla.net/news-detail.cfm?id=#id#' />
</cfloop>

<!--- Generate the feed and save it to a variable. --->
<cffeed action="create" name="#myStruct#" overwrite="true" xmlVar="myXML" />

以上代码效果很好。现在这是我的第二个文件中的代码(因为你可以看到它几乎相同,只是使用不同的表格):

<!--- Get the feed data as a query from the orders table. ---> 
<cfquery name="getNews" datasource="#DSN#">  
    SELECT * FROM NEWS
    WHERE STATUS = 1 
    ORDER BY rdate DESC
</cfquery> 

<cfset myStruct = StructNew() />
<cfset mystruct.link = "http://noobzilla.net" />
    <cfset myStruct.title = "IDE Reviews" />
<cfset mystruct.description = "IDE and SDK Reviews" />
<cfset mystruct.pubDate = Now() />
<cfset mystruct.version = "rss_2.0" />
<cfset myStruct.item = ArrayNew(1) />

<cfloop query="getNews">
    <cfset myStruct.item[currentRow] = StructNew() />
    <cfset myStruct.item[currentRow].guid = structNew() />
    <cfset myStruct.item[currentRow].guid.isPermaLink="YES" />
    <cfset myStruct.item[currentRow].guid.value = 'http://noobzilla.net/news-detail2.cfm?id=#id#' />    
    <cfset myStruct.item[currentRow].pubDate = "#DateFormat(getNews.rdate, "mm/dd/yyyy")#" />
    <cfset myStruct.item[currentRow].title = #title# />
    <cfset myStruct.item[currentRow].description = StructNew() />
    <cfset myStruct.item[currentRow].description.value = '#Left(info, 250)#...' />
    <cfset myStruct.item[currentRow].link = 'http://noobzilla.net/news-detail2.cfm?id=#id#' />
</cfloop>

<!--- Generate the feed and save it to a variable. --->
<cffeed action="create" name="#myStruct#" overwrite="true" xmlVar="myXML" />

第二组代码会产生以下错误:

解析pubDate中指定的日期时出错。 无法将pubDate转换为日期。

3 个答案:

答案 0 :(得分:2)

我会检查getNews.rdate值并确保其接受ColdFusion的任何标准日期或日期/时间格式。

答案 1 :(得分:1)

这是Pragnesh提出的解决方案的代码示例:

<cfif isDate(getNews.rdate)>
    <cfset myStruct.item[currentRow].pubDate = DateFormat(getNews.rdate, "mm/dd/yyyy") />
<cfelse>
    <cfset myStruct.item[currentRow].pubDate = DateFormat(Now(), "mm/dd/yyyy") />
</cfig>

答案 2 :(得分:0)