// 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.Linq; using System.Xml.Linq; namespace E { public class User { public string UserName { get; set; } public List ControlNumber { get; set; } } public class Program { public static void Main(string[] args) { string xmlstr = @" 1297267 1296151 "; XDocument doc = XDocument.Parse(xmlstr); Dictionary dic = doc.Root.Elements("User") .Select(u => new User { UserName = u.Attribute("id").Value, ControlNumber = u.Element("ControlNumbers").Elements("ControlNumber") .Select(cn => int.Parse(cn.Value)).ToList() }) .ToDictionary(u => u.UserName, u => u); foreach(KeyValuePair u in dic) { Console.WriteLine("{0} {1}", u.Key, u.Value.ControlNumber[0]); } } } }