// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Xml.Serialization; namespace E { public class Data1 { public Data1() { Id = "Some value"; } public string Id { get; set; } } [XmlRoot(ElementName="MyData2")] public class Data2 { public Data2() { Id = "Some value"; } [XmlElement(ElementName="MyId")] public string Id { get; set; } } public class Program { public static void Main(string[] args) { XmlSerializer ser1 = new XmlSerializer(typeof(Data1)); ser1.Serialize(Console.Out, new Data1()); XmlSerializer ser2 = new XmlSerializer(typeof(Data2)); ser2.Serialize(Console.Out, new Data2()); } } }