【问题标题】:Can we change XML encoding from utf-8 to utf -16?我们可以将 XML 编码从 utf-8 更改为 utf -16 吗?
【发布时间】:2012-10-08 08:32:21
【问题描述】:

我编写了一个使用 UTF-8 编码生成 XML 的代码。我总是使用 XSD 文件验证 XML。在相同的代码中,我需要 UTF-16 编码。因为我的 XSD 文件之一是 UTF-16 编码。 但在我现有的代码中,它不被接受。它给出了以下错误。

FAILED: Fatal error: Document labelled UTF-16 but has UTF-8 content at filepath/standard.xsd:1.

在 XSD 的第 1 行,这个标签被定义为 <?xml version="1.0" encoding="utf-16"?>

如何使用 utf-8 编码进行验证?

有什么方法可以将 UTF-16 更改为 UTF-8 编码。 提前致谢。

【问题讨论】:

    标签: ruby-on-rails xml utf-8 xsd utf-16


    【解决方案1】:

    您可以使用 Iconv 将编码从 utf16 更改为 utf-8

    Call iconv from Ruby 1.8.7 through system to convert a file from utf-16 to utf-8

    当你编写新文件时,你可以用一个新的标题替换第一行,比如

    <?xml version="1.0" encoding="utf-8" ?>
    

    Ruby - Open file, find and replace multiple lines

    如果您以其他方式需要它,请更改函数中的结尾。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-29
      • 2015-09-19
      • 2012-06-30
      • 2014-01-18
      • 1970-01-01
      • 2011-06-23
      • 2010-10-19
      • 1970-01-01
      相关资源
      最近更新 更多