当我尝试将使用 UTF-16 编码的 xml 文件转换为 ISO-8859-1 时,我看到像Â
.
您能否建议一些解决方案来删除损坏的字符?我想要 ISO 编码格式的 XML。
这是我的代码,
using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.AppSettings.Get("SqlConn")))
{
sqlConnection.Open();
using (SqlCommand sqlCommand = new SqlCommand())
{
sqlCommand.CommandTimeout = 0;
sqlCommand.CommandText = commandText;
sqlCommand.Connection = sqlConnection;
// the data from database data is UTF encoded
using (StreamWriter textwriterISO = new StreamWriter(path + "_out.XML", false, Encoding.GetEncoding("ISO-8859-1")))
{
SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
Console.WriteLine("Writing results.This could take a very long time.");
while (sqlDataReader.Read())
{
for (int i = 0; i < sqlDataReader.FieldCount; i++)
{
byte[] arr = System.Text.Encoding.GetEncoding(28591).GetBytes(sqlDataReader[i].ToString());
string ascii = Encoding.GetEncoding("UTF-8").GetString(arr);
textwriter.WriteLine(sqlDataReader.GetName(i),ascii));
}
textwriter.Flush();
}
}
}
}