views:

72

answers:

1

So I'm trying to parse some XML from the twitter API and for some reason the LINQ query below only returns 1 row. When I step through the code to view the raw XML it's the usual 20+ items so I'm not sure what I'm doing wrong here.

Any help for a LINQ to XML newbie?

            List<TwitterStatus> StatusCollection = new List<TwitterStatus>();
            XDocument xdoc = XDocument.Parse(xmldata);

            StatusCollection = (from status in xdoc.Descendants("statuses")
                                select new TwitterStatus
                                {
                                    Text = status.Element("status").Element("text").Value,
                                    User = status.Element("status").Element("user").Element("screen_name").Value
                                }).ToList();
+1  A: 

Now I dont know the form of twitter XML, but could it be that the element "statuses", contains multiple "status" elements. So Desecendants("statuses") only find one element. Would you not need to do

StatusCollection = (from status in xdoc.Descendants("status") select new TwitterStatus {
Text = status.Element("text").Value,
User = status.Element("user").Element("screen_name").Value }).ToList();

SteveCl