I am trying to query an XML file. Below query returns the first element in the sequence. Wondering how to get all elements in the sequence as a List. rsltQuest is of type List of XElement.
rsltQuest = doc1.Descendants(xmlns + "QUESTION") .Where(t => t开发者_JS百科.Attribute("ANSWER").Value == "no").ToList();`
Thanks for your advices. M
I see two issues but both should not cause the result to be a one element list (provided there are more than one QUESTION elements having an ANSWER attribute with value "no"):
- You close one more parenthesis than you open.
- You could get a null pointer exception if there is an QUESTION element having no ANSWER attribute.
So, are you sure the data contains more than one QUESTION with ANSWER="no"? Or maybe this is a namespace issue?
EDIT: Maybe you should try (string)(t.Attribute("ANSWER")) == "no"
精彩评论