tags:

views:

235

answers:

1

Given this xml document:

<projects><project><name>sample project</name><location>http://somewhere.com/&lt;/location&gt;&lt;/project&gt;&lt;/projects&gt;

And this linq to xml statement for retrieving name/location elements and creating a new Project object:

return xmlDocumentFromAbove.Descendants("project").Select(p => new Project(p.Element("Name").Value, p.Element("Location").Value));

I keep getting a NRE where I am accessing p.Element("Name").Value. Am I missing something obvious here?

Thanks!

+2  A: 

"Name" should be "name" - likewise "Location" to "location".

return xmlDocumentFromAbove.Descendants("project").Select(p =>
    new  Project(p.Element("name").Value, p.Element("location").Value));
Marc Gravell