title: Getting byte array from XML string with encoding
body: <p>I have XML content in a string that defines its encoding in its declaration. I want to get a byte array from that string and download it to a client browser.</p>
  
  <p>The following works, but I'm not that experienced with encoding and am wondering <strong>will I cause something to blow up if I do it this way?</strong>  </p>
  
  <p>Basically, I'm getting the encoding from the declaration, and using that encoding to convert the XML string to a byte array. <strong>Is that how it should work?</strong>      </p>
  
  <pre><code>var xdoc = XDocument.Parse(xmlString);
  var encoding = System.Text.Encoding.GetEncoding(xdoc.Document.Declaration.Encoding);
  
  var encoded = encoding.GetBytes(xmlString);
  
  Response.AppendHeader("Content-Disposition", "attachment; filename=" + xmlData.FileName);
  return File(encoded, "text/plain");
  </code></pre>