What is most likely happened is that you loaded your document as an XElement
and therefore x
is already referring to the root node projects
. Your queries have to be relative to that node and that node clearly doesn't have a projects
child. You're trying to select the child project
elements relative to your projects
node so your query should be:
var projects = x.XPathSelectElements("project");
Though in this case, you don't really need to use xpath, just use the Elements()
method instead.
var projects = x.Elements("project");
You generally should use XDocument
objects to load the document instead of XElement
, otherwise you'd run into these kinds of problems.