LINQ to XML query attributes

Posted by kb on Stack Overflow See other posts from Stack Overflow or by kb
Published on 2010-04-07T08:59:25Z Indexed on 2010/04/07 9:03 UTC
Read the original article Hit count: 231

Filed under:
|

Hi

using LINQ to XML, this is a sample of my XML

<shows>
 <Show Code="456" Name="My Event Name">
   <Event Code="2453" VenueCode="39" Date="2010-04-13 10:30:00" /> 
   <Event Code="2454" VenueCode="39" Date="2010-04-13 13:30:00" /> 
   <Event Code="2455" VenueCode="39" Date="2010-04-14 10:30:00"  /> 
   <Event Code="2456" VenueCode="39" Date="2010-04-14 13:30:00" /> 
   <Event Code="2457" VenueCode="39" Date="2010-04-15 10:30:00" /> 
 </Show>

 <Show... />
 <Show... />
</shows>

How do I return a list of the Dates for a specfic show? I am passing the show code ("456") in the querystring and want all the dates/times returned as a list.

This is the code i have so far:

XDocument xDoc = XDocument.Load("path to xml");

            var feeds = from feed in xDoc.Descendants("Show")
                        where feed.Attribute("Code").Equals("456")
                        select new
                        {
                            EventDate = feed.Attribute("Date").Value
                        };

            foreach(var feed in feeds)
            {
                Response.Write(feed.EventDate + "<br />");
            }

But i get no results returned

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about Xml