Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 712821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:53:28+00:00 2026-05-14T04:53:28+00:00

using LINQ to XML, this is a sample of my XML <shows> <Show Code=456

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:53:29+00:00Added an answer on May 14, 2026 at 4:53 am

    The attribute isn’t going to equal “456” – it’s an attribute, not a string. However, if you convert it to a string first, it will work.

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

    An alternative would be to int to make sure it’s numeric:

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

    EDIT: Okay, I’ve now got this as a short but complete program to show it working.

    Note that your original code will only work if the “Show” element has a “Date” attribute – which it doesn’t in your sample XML. Note that it’s trying to take the “Date” from the “Show” element not the “Event” element. I’m not sure what you really wanted to do here, so I’ve changed the code to just cast to DateTime? instead. The code below works and prints 1 (i.e. it’s found the single Show element matching the code):

    using System;
    using System.Linq;
    using System.Xml.Linq;
    
    public static class Test
    {    
        static void Main(string[] args)
        {
            XDocument xDoc = XDocument.Load("shows.xml");
            var feeds = from feed in xDoc.Descendants("Show")
                        where (int) feed.Attribute("Code") == 456
                        select new
                        {
                            EventDate = (DateTime?) feed.Attribute("Date")
                        };
    
            Console.WriteLine(feeds.Count());
        }
    }
    

    If you’re actually trying to find every event date within the show, you need another “from” clause to make it iterate over the events within the show:

    var events = from feed in xDoc.Descendants("Show")
                 where (int) feed.Attribute("Code") == 456
                 // We can't use event as an identifier, unfortunately
                 from ev in feed.Elements("Event")
                 select new
                 {
                     EventDate = (DateTime?) ev.Attribute("Date")
                 };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.