using System.Xml.Serialization;
public static void Main()
var MyRestaurant = new Restaurant() {
Street="11740 Washington Blvd",
XmlSerializer xs = new XmlSerializer( typeof(Restaurant) );
XmlSerializerNamespaces xmlnsEmpty = new XmlSerializerNamespaces();
xmlnsEmpty.Add( "", "" );
XmlWriterSettings settings = new XmlWriterSettings();
settings.Encoding = System.Text.Encoding.ASCII;
settings.CheckCharacters = false;
MemoryStream ms = new MemoryStream();
using ( XmlWriter writer = XmlWriter.Create( ms, settings ) ) {
xs.Serialize( writer, MyRestaurant, xmlnsEmpty );
Console.WriteLine( settings.Encoding.GetString( ms.ToArray() ) );
using ( StreamWriter writer = new StreamWriter( ms, System.Text.Encoding.ASCII ) ) {
xs.Serialize( writer, MyRestaurant, xmlnsEmpty );
Console.WriteLine( settings.Encoding.GetString( ms.ToArray() ) );
public class Restaurant {