Question: This is my XML structure, which is a list of events that each contains a list of event times. I need to return a list of 'TIME' values, but im stuck on how to get these values (Note that I need to query this list & filter by 'Id')

![enter image description here](https://i.stack.imgur.com/mk33u.png)

Code so far:

```
public IEnumerable<EventFeed> GetEventDatesByEventId(int eventId)
    {
        return (from feed in xmlDoc.Descendants("Event")
                where (int)feed.Element("Id") == eventId
                from ev in feed.Elements("Times")
                select new EventFeed()
                {
                    EventDate = (DateTime)ev.Element("Time")
                }).ToList().OrderByDescending(x => x.EventDate);
    }

```

thanks
kb

Answer: 
Close, you'll need to select the `<Times>` node first or use `Descendants` since `<Time>` is below `EventTime`:

```
return (from feed in xmlDoc.Descendants("Event")
        where (int)feed.Element("Id") == eventId
        from et in feed.Element("Times").Elements("EventTime")
        select new EventFeed()
        {
            EventDate = (DateTime)et.Element("Time")
        }).ToList().OrderByDescending(x => x.EventDate);

```

Sample:

```
string xml = @"<?xml version=""1.0"" ?>
<Events>
    <Event>
        <Id>542</Id>
        <Times>
            <EventTime>
                <Time>2011-11-28T14:00:00</Time>
            </EventTime>
            <EventTime>
                <Time>2011-11-30T10:00:00</Time>
            </EventTime>
            <EventTime>
                <Time>2011-11-30T09:00:00</Time>
            </EventTime>
        </Times>
    </Event>
</Events>";

int eventId = 542;
foreach (var evt in GetEvents(XDocument.Parse(xml), eventId)
{
    Console.WriteLine("{0}", evt.EventDate);
}

```

Outputs:

```
11/30/2011 10:00:00
11/30/2011 09:00:00
11/28/2011 14:00:00

```
This is straight off the bat and untested but something like this might do it, or at least get you started

```
        xmlDoc.Descendants("Event")
            .Where(ev => (int) ev.Element("Id") == eventId)
            .SelectMany(ev => ev.Element("Times").Elements("EventTime")
                                                 .Select(et => et.Element("Time").Value));

```

You can alter the final select to build your EventFeed class as follows:

```
.Select(et => new EventFeed{EventDate = (DateTime)et.Element("Time").Value}));

```