Regex 如何更换&;书信电报;与<;冷若冰霜
我正在使用ColdFusion从数据库条目创建XML文档,创建XML时,Regex 如何更换&;书信电报;与<;冷若冰霜,regex,xml,coldfusion,rss,Regex,Xml,Coldfusion,Rss,我正在使用ColdFusion从数据库条目创建XML文档,创建XML时,的格式为和。因此,在创建XML之前,有没有办法将更改为简单答案: 编写文件时不要XmlFormat(),这就是导致出现双重编码的原因 详细回答: 我建议您使用映射来创建提要: <cfquery name="messages" datasource="showcase_Uk"> select id, uploadDate, name, description, 'yes' as isPermaLink
的格式为
和
。因此,在创建XML之前,有没有办法将
更改为简单答案:
编写文件时不要XmlFormat()
,这就是导致出现双重编码的原因
详细回答:
我建议您使用映射来创建提要:
<cfquery name="messages" datasource="showcase_Uk">
select
id, uploadDate, name, description, 'yes' as isPermaLink
from
t_items
where
pid = 2 and spid = 45
</cfquery>
<cfset feedMeta = {
version: "rss_2.0",
title: "Examples",
link: "http://showcase.com",
publisheddate: Now(),
description: "Examples from UK Showcase"
}>
<cfset feedMap = {
title: "name",
content: "description",
publisheddate: "uploadDate",
id: "id",
idpermalink: "isPermaLink"
}>
<cffeed
action="create"
properties="#feedMeta#" columnMap="#feedMap#" query="#messages#"
xmlvar="feedXml"
>
<cffile
action="write"
file="#ExpandPath('/ukshowcasefeed.xml')#" nameconflict="overwrite" charset="utf-8"
output="#feedXml#"
>
附议。您专门将完全有效的XML转换为转义XML,因为您要通过xmlFormat()
传递它。如果你不想那样做。。。那就不要了。反省一下,xmlFormat()
是一个名称非常糟糕的函数。它应该是encodeForCData()
或something@AdamCameron在这种情况下,甚至没有必要使用它。我在XmlFormat()
中遇到的问题是,它鼓励人们将XML视为字符串,这也是OP犯下错误的基础。XML是一种数据结构,就像结构一样,应该这样对待。请参阅我更新的答案。
<cfquery name="messages" datasource="showcase_Uk">
select
id, uploadDate, name, description, 'yes' as isPermaLink
from
t_items
where
pid = 2 and spid = 45
</cfquery>
<cfset feedMeta = {
version: "rss_2.0",
title: "Examples",
link: "http://showcase.com",
publisheddate: Now(),
description: "Examples from UK Showcase"
}>
<cfset feedMap = {
title: "name",
content: "description",
publisheddate: "uploadDate",
id: "id",
idpermalink: "isPermaLink"
}>
<cffeed
action="create"
properties="#feedMeta#" columnMap="#feedMap#" query="#messages#"
xmlvar="feedXml"
>
<cffile
action="write"
file="#ExpandPath('/ukshowcasefeed.xml')#" nameconflict="overwrite" charset="utf-8"
output="#feedXml#"
>
<cfquery name="messages" datasource="showcase_Uk">
select
id,
'yes' as idpermalink
uploadDate as publisheddate,
name as title,
description as content
from
t_items
where
pid = 2 and spid = 45
</cfquery>
<cffeed
action="create"
properties="#feedMeta#" query="#messages#"
xmlvar="feedXml"
>