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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:26:15+00:00 2026-05-28T17:26:15+00:00

I have been searching for an answer for 24 hours, but I did not

  • 0

I have been searching for an answer for 24 hours, but I did not find it. I am new to C#. I have found a tutorial, from where I have used this code:

XDocument loadedCustomData = XDocument.Load("PeopleCustom.xml");
var filteredData = from c in loadedCustomData.Descendants("Person")
                           where c.Attribute("Age").Value == current.ToString()
                           select new Person
                           {
                               FirstName = (string)c.Attribute("FirstName").Value,
                           };

listBox1.ItemsSource = filteredData;
public class Person
    {
        string firstname;
        string lastname;
        int age;

        public string FirstName
        {
            get { return firstname; }
            set { firstname = value; }
        }

        public string LastName
        {
            get { return lastname; }
            set { lastname = value; }
        }


        public int Age
        {
            get { return age; }
            set { age = value; }
        }


    }

XML is like this:

<People>
<Person
   FirstName="Kate"
   LastName="Smith"
   Age="1" />
<Person 
       ...
               />
</People>

It works, but it puts all output into listbox. I want strings. I tried to get string from list box (like this listBox1.Items[0].ToString();), but all I get is something like this: ProjectName.MainPage+Person. I also tried to get it from filteredData, but no success.
Is there any way to get data from XML to strings? Thank you in advance for your answer

  • 1 1 Answer
  • 1 View
  • 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-28T17:26:15+00:00Added an answer on May 28, 2026 at 5:26 pm

    this code

    XDocument loadedCustomData = XDocument.Load("PeopleCustom.xml");
    var filteredData = from c in loadedCustomData.Descendants("Person")
                               where c.Attribute("Age").Value == current.ToString()
                               select new Person
                               {
                                   FirstName = (string)c.Attribute("FirstName").Value,
                               };
    

    makes a list of Person objects: select New Person{.....}

    If you want a list of string of the Person‘s first name, then all you have to do is change what object the LINQ is creating….

    select (string)c.Attribute("FirstName").Value );
    

    now, it makes a new string from the FirstName attribute.

    after this linq is run, you will basically have a linq object that will produce a list of strings. if you want a List then modify like this:

    XDocument loadedCustomData = XDocument.Load("PeopleCustom.xml");
    var filteredData =( from c in loadedCustomData.Descendants("Person")
                               where c.Attribute("Age").Value == current.ToString()
                               select (string)c.Attribute("FirstName").Value ).ToList();
    

    if you want the first string in the list…

    filterdData.First();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been searching desperately for an answer to this question, but not found
I have been searching everywhere but I could not find an answer. I need
I have been searching for an answer to this question but cannot find anything
I have been searching for an answer to this but can't find it on
I have been searching for an answer to this dilemma but found nothing. I
I have been searching for an answer to this but cannot find a simple
I have been searching for the answer to this but cant seem to find
I have been searching for a few hours and cant seem to find answer
I have been searching around using Google but I can't find an answer to
I have been searching around for an answer to this but I can't seem

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.