Linq XML query with nested loop - 1

sian

New Member
In this question, if I need to get "date" included in the output, what changes should be made?When I included\[code\]let dt = l.Element("Date").Value\[/code\]It gives, "Object reference not set to an instance of an object"\[code\]var query = from l in doc.Descendants("L1") let dt = l.Element("Date").Value let id = l.Attribute("id").Value from subject in l.Descendants("Subject") select new { Date = dt, Id = id, SubjectName = (string)subject.Attribute("SubjectName"), Score = (string)subject.Attribute("Score") };foreach (var result in query){ Console.WriteLine(result);}\[/code\]
 
Back
Top