2

Given this xml document:

<projects><project><name>sample project</name><location>http://somewhere.com/</location></project></projects>

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!

1 Answer 1

3

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

return xmlDocumentFromAbove.Descendants("project").Select(p =>
    new  Project(p.Element("name").Value, p.Element("location").Value));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.