Skip to content

Instantly share code, notes, and snippets.

@hyrmn
Created July 26, 2010 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyrmn/491261 to your computer and use it in GitHub Desktop.
Save hyrmn/491261 to your computer and use it in GitHub Desktop.
string xmlString = SerializeResultsToXmlString(response);
return Content(xmlString, "application/xml", Encoding.UTF8);
private string SerializeResultsToXmlString(ApiResponse response)
{
var memoryStream = new MemoryStream();
var xs = new XmlSerializer(typeof(ApiResponse));
var xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
xs.Serialize(xmlTextWriter, response);
memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
return UtfByteArrayToString(memoryStream.ToArray());
}
private static String UtfByteArrayToString(Byte[] characters)
{
var encoding = new UTF8Encoding();
return encoding.GetString(characters);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment