【问题标题】:How to convert special characters in utf-8 format while creating a xml file in ColdFusion如何在 ColdFusion 中创建 xml 文件时转换 utf-8 格式的特殊字符
【发布时间】:2010-12-17 17:12:15
【问题描述】:

我正在使用 ColdFusion 5 并尝试在创建 xml 文件时将特殊字符转换为 utf-8

我为此使用 xmlFormat(),但是当我解析 xml 文件时,它会给出如下错误:

解析 xml 失败:

mountainhomes/xdeadline_listings_wsj.xml:539: 解析器错误:输入不是正确的 UTF-8,表示编码!

字节:0x96 0x31 0x28 0x32

5BA,开放式厨房,餐厅和家庭区,带燃气灶。下层有 2 个车库

                  Â

【问题讨论】:

  • 非常怀疑你会找到可以帮助你解决 CF 5 问题的人。
  • CF 5 确实带来了一些挑战。可能最简单的(虽然必须耗费时间)是一个 UDF(你能在 CF5 中做那些吗?),它循环遍历常见字符并执行 Replace
  • xdeadline_listings_wsj.xml 的编码是什么?只是需要适当的声明还是重新编码?

标签: encoding coldfusion utf-8


【解决方案1】:

您可以使用像 Demoronize (http://www.cflib.org/index.cfm?event=page.udfbyid&udfid=725) 这样的 UDF 来解决这个问题。我使用 dpaste.org(原始视图)来查找违规字符,获取正确的 ascii 代码,并将其添加到 Demoronize 以过滤这些垃圾字符。下面是我添加到原始 UDF 中的列表,用于取出 Word 引号、省略号等。

text = Replace(text, Chr(96), "'", "All");
text = Replace(text, Chr(198), "'", "All");
text = Replace(text, Chr(8216), "'", "All");
text = Replace(text, Chr(8217), "'", "All");
text = Replace(text, Chr(8220), """", "All");
text = Replace(text, Chr(8221), """", "All");
text = Replace(text, Chr(8230), "...", "All");
text = Replace(text, Chr(244), """", "All");
text = Replace(text, Chr(246), """", "All");
text = Replace(text, Chr(8211), "-", "All");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-29
    相关资源
    最近更新 更多