// 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 Data { public string AssetText { get; set; } public string MyField { get; set; } } public class Program { public static void Main(string[] args) { string xmlstr = @" 44 my first Asset Text first myfield belongs to id 44 my second Asset Text next myfield belongs to id 44 45 my third Asset Text first myfield belongs to id 45 "; XDocument xmldoc = XDocument.Parse(xmlstr); IEnumerable pvsel = xmldoc.Root.Element("member").Elements("ProductView").Where(pv => pv.Element("ViewId").Value == "44"); List alld = pvsel.Elements("pair").Select(p => new Data { AssetText = p.Element("AssetText").Element("Text").Value, MyField = p.Element("myfield").Element("Text").Value }).ToList(); foreach(Data d in alld) { Console.WriteLine(d.AssetText + " : " + d.MyField); } } } }