// Collection of code snippets by Arne Vajhøj
// posted to eksperten.dk, usenet and other places (2002-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");
IEnumerable ats = pvsel.Elements("AssetText").Select(elm => elm.Element("Text").Value);
IEnumerable mfs = pvsel.Elements("myfield").Select(elm => elm.Element("Text").Value);
List alld = ats.Zip(mfs, (at,mf) => new Data { AssetText=at, MyField=mf }).ToList();
foreach(Data d in alld)
{
Console.WriteLine(d.AssetText + " : " + d.MyField);
}
}
}
}