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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:00:01+00:00 2026-05-30T00:00:01+00:00

I am new to C# and I am trying to read an XML file

  • 0

I am new to C# and I am trying to read an XML file and transfer its contents to C# object(s).

e.g. An example XML file could be:

<people>
    <person>
        <name>Person 1</name>
        <age>21</age>
    </person>
    <person>
        <name>Person 2</name>
        <age>22</age>
    </person>
</people>

.. could be mapped to an array of C# class called ‘Person’:

Person[] people;

Where a Person object could contain the following fields:

string name;
uint age;
  • 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-30T00:00:02+00:00Added an answer on May 30, 2026 at 12:00 am

    It sounds like you want use XML serialization. There is a lot already out there, but this is a pretty simple example.
    http://www.switchonthecode.com/tutorials/csharp-tutorial-xml-serialization

    The snippet you want is about 1/4 of the way down:

    XmlSerializer deserializer = new XmlSerializer(typeof(List<Movie>));
    TextReader textReader = new StreamReader(@"C:\movie.xml");
    List<Movie> movies; 
    movies = (List<Movie>)deserializer.Deserialize(textReader);
    textReader.Close();
    

    Hopefully, this helps

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

Sidebar

Related Questions

Trying to read into an object the following XML file (can be changed) into
I am trying to read a XML file and display its content in a
I'm trying to read an object from a XML file using XMLDecoder. The construction
I am trying to read the book.xml file provided as an example on the
I am trying to read a element form a xml file to add new
I'm trying to read a log file of log4net: FileStream fs = new FileStream(filePath,
Hi I am trying to read XML File using XLinq and binding the values
I'm currently trying to READ XML file from the client machine where the user
I have created new class to read the data from xml file, which looks
I am currently trying to read from an xml file which records the jobs

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.