I\'ve chosen the title here as my problem is I need to get the Item nodes mentioned in the example. I have the following XML and am having problems using LINQ to query it, I
I had a blank Namespace Declaration in my XML I hadn't noticed once I added this into my code it worked - forgot LINQ is very NameSpace oriented!
XNamespace ns = "http://example.org/namespace";
var ids = element.Element(ns + "items")
.Elements("item")
.Select(item => item.Element("id").Value);
Assuming element
is your <a:entry>
element:
var ids = element.Element("items")
.Elements("item")
.Select(item => item.Element("id").Value);
The Element
and Elements
methods return only direct children, not all descendants, so it doesn't return the <items>
element which is under <data>