title: XML Declaration and conversion
body: <p>I'm getting an xml file that I want to convert to UTF-8 from ansi. Initially my code was working because the original xml file didnot have an xml declaration. but recently that the original xml file comes with the following declaration:</p>
  
  <pre><code>  &lt;?xml version="1.0" encoding="WINDOWS-1256"?&gt;
  </code></pre>
  
  <p>In my code I'm doing the conversion from ansi to uft-8 and adding another header:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  </code></pre>
  
  <p>So after I pass the new file through my code for conversion to utf-8, the new declaration is:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;?xml version="1.0" encoding="WINDOWS-1256"?&gt;
  </code></pre>
  
  <p>which i believe is invalid.</p>
  
  <p>Below is my code:</p>
  
  <pre><code>Encoding utf8 = new UTF8Encoding(false);
  Encoding ansi = Encoding.GetEncoding(1256);
  System.Threading.Thread.Sleep(2000);
  
  string xml = File.ReadAllText(FileName,ansi);
  //   XDocument xmlDoc = XDocument.Parse(xml);
  //  Console.WriteLine("1st");
  File.WriteAllText(
        FileName,
        @"&lt;?xml version=""1.0"" encoding=""utf-8""?&gt;" +  xml.ToString(),
        utf8
  );
  
  
  if (File.Exists(destinationFile))
      File.Delete(destinationFile);
  
  File.Copy(FileName, destinationFile,true);
  Console.WriteLine("File Copied" + "  " + DateTime.Now.ToString("HH:mm:ss tt")); // for troubleshoooting only
  Console.WriteLine("Press \'q\' to quit."); 
  Console.Write(CrL);
  </code></pre>
  
  <p>The output of this coming out as garbled arabic text with two declarations. Where am I wrong in the code.</p>