> i've got the following xml structure:
>
[quoted text clipped - 13 lines]
> now i'd like to build a query which will select all <item> elements in
> a given section (e.g. books).
XDocument doc = XDocument.Load(@"catalog.xml");
IEnumerable<XElement> bookItems =
doc.Root.Element("books").Elements("item");
IEnumerable<XElement> cdItems =
doc.Root.Element("cds").Elements("item");
That simply selects the 'item' XElement objects. If you want to populate
some anonymous type then do it like this:
XDocument doc = XDocument.Load(@"..\..\XMLFile1.xml");
var query =
from item in doc.Root.Element("books").Elements("item")
select new { key = (string)item.Attribute("key"), value
= (string)item.Attribute("value") };
foreach (var item in query)
{
Console.WriteLine("{0}: {1}.", item.key, item.value);
}

Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Matthias S. - 16 Apr 2008 18:34 GMT
that helped. thank you a ton.

Signature
> > i've got the following xml structure:
> >
[quoted text clipped - 32 lines]
> Console.WriteLine("{0}: {1}.", item.key, item.value);
> }