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 3453916
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:25:50+00:00 2026-05-18T09:25:50+00:00

Thank you in advance, this is a great resource. I believe the code explains

  • 0

Thank you in advance, this is a great resource.

I believe the code explains itself, but just in case I am being arrogant I will explain myself.

My program lists movies, to a treeview, according to the drop down lists selected genre. Each movie has a few genres, ergo the nested genres.

This is the XML:

   <movie>
    <title>2012</title>
    <director>Roland Emmerich</director>
    <writtenBy> 
        <writter>Roland Emmerich,</writter>
        <writter>Harald Kloser</writter>
    </writtenBy>
    <releaseDate>12-Nov-2009</releaseDate>
    <actors>
        <actor>John Cusack,</actor>
        <actor>Thandie Newton, </actor>
        <actor>Chiwetel Ejiofor</actor>
    </actors>
    <filePath>H:\2012\2012.avi</filePath>
    <picPath>~\image\2012.jpg</picPath>
    <runningTime>158 min</runningTime>
    <plot>Dr. Adrian Helmsley, part of a worldwide geophysical team investigating the effect on the earth of radiation from unprecedented solar storms, learns that the earth's core is heating up. He warns U.S. President Thomas Wilson that the crust of the earth is becoming unstable and that without proper preparations for saving a fraction of the world's population, the entire race is doomed. Meanwhile, writer Jackson Curtis stumbles on the same information. While the world's leaders race to build "arks" to escape the impending cataclysm, Curtis struggles to find a way to save his family. Meanwhile, volcanic eruptions and earthquakes of unprecedented strength wreak havoc around the world. </plot>
    <trailer>http://2012-movie-trailer.blogspot.com/</trailer>
    <genres>
        <genre>Action</genre>
        <genre>Adventure</genre>
        <genre>Drama</genre>
    </genres>
    <rated>PG-13</rated>
</movie>

This is the code:


 string selectedGenre = this.ddlGenre.SelectedItem.ToString();
            XDocument xmldoc = XDocument.Load(Server.MapPath("~/App_Data/movie.xml"));

 List<Movie> movies =
                (from movie in xmldoc.Descendants("movie")
                 // The treeView doesn't exist
                 where movie.Elements("genres").Elements("genre").ToString() == selectedGenre

  select new Movie
                {
                     Title = movie.Element("title").Value
                }).ToList();

  foreach (var movie in movies)
                {
                    TreeNode myNode = new TreeNode();
                    myNode.Text = movie.Title;
                    TreeView1.Nodes.Add(myNode);
                }
  • 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-18T09:25:51+00:00Added an answer on May 18, 2026 at 9:25 am

    Change your code to

    List<Movie> movies =
                    (from movie in xmldoc.Descendants("movie")
                    where movie.Elements("genres").Elements("genre").Any(e => e.Value == selectedGenre)
    
                    select new Movie
                    {
                        Title = movie.Element("title").Value
                    }).ToList();
    

    This is because there are more than 1 genre node, so you’ll have to check if any of them match instead of just the first.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if this is too simple, but thanks in advance for helping. This is
I've got some multi threaded code that typically runs great, but every so often
Thanks in Advance for reading and answer this question. I got button in asp
First of all thanks in advance, this has been very frustrating and I'm hoping
This is a total newbie question, so thanks in advance. I'm trying to get
Greetings and thank you in advance for the help. I created a user control
what is webparts in asp.net? a simple example on webparts. thank you in advance.
I have this .htaccess file but I would like it to only do this
I am having great problems solving this one: I have a mysql database encoding
This article is really great and awesome. This is from the topic ASP.NET MVC

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.