// 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.Collections.Generic; using System.Xml; using System.Xml.Serialization; namespace E { public class type1 { public String tekst { get; set; } } public class type2 { public String tekst { get; set; } } public class type3 { public String tekst { get; set; } } public class xmltest { [XmlElement] public List type1 { get; set; } [XmlElement] public List type2 { get; set; } [XmlElement] public List type3 { get; set; } } public class Program { public static void Dump(xmltest o) { Console.WriteLine("type1:"); foreach(type1 t1 in o.type1) { Console.WriteLine(" {0}", t1.tekst); } Console.WriteLine("type2:"); foreach(type2 t2 in o.type2) { Console.WriteLine(" {0}", t2.tekst); } Console.WriteLine("type3:"); foreach(type3 t3 in o.type3) { Console.WriteLine(" {0}", t3.tekst); } } public static void Main(string[] args) { XmlSerializer ser = new XmlSerializer(typeof(xmltest)); XmlReader rdr = new XmlTextReader("/Work/test.xml"); while(rdr.Read()) { switch(rdr.NodeType) { case XmlNodeType.Element: XmlReader subrdr = rdr.ReadSubtree(); xmltest o = (xmltest)ser.Deserialize(subrdr); Dump(o); subrdr.Close(); break; default: // ignore break; } } rdr.Close(); } } }