I’m new to Linq to Xml. I have a very simple xml file like this:
<Items> <Item> <Stuff>Strings</Stuff> </Item> <Item> <Stuff>Strings</Stuff> </Item> </Items>
And I’m trying to query it like this:
XDocument doc = XDocument.Load(myStream) from node in doc.Descendants(XName.Get('Item')) select new { Stuff = node.Element(XName.Get('Stuff')).Value }
But doc.Descendents(XName.Get(‘Item’)) returns null. Something is wrong with my understanding here.
Your code actually works:
It should be noted that if the elements are not qualified with namespaces, then you don’t really need XName: