// 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 { [XmlRoot(Namespace="http://foobar")] public class MyRoot { public string A { get; set; } public int B { get; set; } public int C { get; set; } public int D { get; set; } } [XmlRoot(Namespace="http://foobar")] public class MyRoot2 { [XmlElement(Namespace="")] public string A { get; set; } [XmlElement(Namespace="")] public int B { get; set; } [XmlElement(Namespace="")] public int C { get; set; } [XmlElement(Namespace="")] public int D { get; set; } } public class Program { public static void Main(string[] args) { MyRoot mr = new MyRoot{ A="ABC", B=1, C=2, D=3 }; XmlSerializer ser = new XmlSerializer(typeof(MyRoot)); ser.Serialize(Console.Out, mr); MyRoot2 mr2 = new MyRoot2{ A="ABC", B=1, C=2, D=3 }; XmlSerializer ser2 = new XmlSerializer(typeof(MyRoot2)); ser2.Serialize(Console.Out, mr2); } } }