When I tried to convert the xml file with a UTF-16 encoding to ISO-8859-1, I am seeing broken characters like Â.
Can you please suggest some solution to remove the broken characters? I want the XML in an ISO encoded format.
Here is my code,
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();
}
}
}
}