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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:03:41+00:00 2026-06-12T18:03:41+00:00

Probably this may be very basic question but I’m working on a small example

  • 0

Probably this may be very basic question but I’m working on a small example project for my understanding and I need some help here to finish this.

public class XMlExample : INotifyPropertyChanged
        {
            [XmlElement("ID")]
            public string ID { get; set; } //Textbox
            [XmlAttribute("Initial")]
            public string Initial { get; set; } //Textbox



            public event PropertyChangedEventHandler PropertyChanged;
        }
public class Details //Datagrid
                {
                    [XmlElement("FirstName")]
                    public string FirstName { get; set; }
                    [XmlElement("LastName")]
                    public string LastName { get; set; }
                }

This is the in-completed function:

Read Write Function:
Button1 to read XML file:

 XmlSerializer deserializer = new XmlSerializer(typeof(XMlExample));
            TextReader textReader = new StreamReader(@"C:\test\testserialization.xml");
            XMlExample xmlexmaple;
            xmlexmaple = (XMlExample)deserializer.Deserialize(textReader);
            textReader.Close();

Button 2 to write XML file:

XmlSerializer serializer = new XmlSerializer(typeof(XMlExample));
            TextWriter textWriter = new StreamWriter(@"C:\test\testserialization.xml");
            serializer.Serialize(textWriter, XXXX);
            textWriter.Close();

Please somebody assist me that How can i get the values from textbox and datagrid to write as a xml file and how can i read that back to the interface. Thank you.

  • 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-06-12T18:03:43+00:00Added an answer on June 12, 2026 at 6:03 pm

    To serialize/deserialize the Datagrid, you can add a property for it in your XMLExample Class and add the Serializable attribute to both classes.

    [Serializable]
    public class XMLExample : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
    
        public XMLExample()
        {
            ID = "Spaghetti";
            Initial = "Linguini";
            Details = new List<Detail>();
        }
    
        public string ID { get; set; } // Textbox
        public string Initial { get; set; } // Textbox
        public List<Detail> Details { get; set; } // Datagrid
    }
    
    [Serializable]
    public class Detail 
    {
        public Detail()
        {
            // default values, if appropriate.
            FirstName = "John"; 
            LastName = "Shaw";
        }
    
        [XmlElement("FirstName")]
        public string FirstName { get; set; }
        [XmlElement("LastName")]
        public string LastName { get; set; }
    }
    

    After deserializing, in your Button1 handler, you can populate your user interface controls appropriately. Before serializing the class, in your Button2 handler, you’ll need to populate the properties in your class appropriately.

    XmlSerializer _serializer = new XmlSerializer(typeof(XMLExample));
    XMLExample _example = new XMLExample();
    
    // Read file.
    using (TextReader textReader = new StreamReader(@"C:\test\testserialization.xml"))
    {
        _example = (XMLExample)_serializer.Deserialize(textReader);
        textReader.Close();
    }
    
    // Populate user interface from the class.
    textBox1.Text = _example.ID;
    textBox2.Text = _example.Initial;
    // etc...
    
    // Update class from user interface
    _example.Details.Add(new Detail() { FirstName = "John", LastName = "Doe" });
    _example.Details.Add(new Detail() { FirstName = "Jane", LastName = "Doe" });
    
    // Write file.
    using (TextWriter textWriter = new StreamWriter(@"C:\test\testserialization.xml"))
    {
        _serializer.Serialize(textWriter, _example);
        textWriter.Close();
    }
    

    testserialization.xml

    <?xml version="1.0" encoding="utf-8"?>
    <XMLExample xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
      xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <ID>Spaghetti</ID>
      <Initial>Linguini</Initial>
      <Details>
        <Detail>
          <FirstName>John</FirstName>
          <LastName>Doe</LastName>
        </Detail>
        <Detail>
          <FirstName>Jane</FirstName>
          <LastName>Doe</LastName>
        </Detail>
      </Details>
    </XMLExample>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may be a dumb question, I have tried googling but I am probably
This may sounds like a stupid question but can't find anything on google, probably
This is probably something very basic, but my Erlang installation is doggedly rejecting my
This is probably very basic, but it's giving me a headache, and I'm not
This may sound like a very stupid question - and probably is! For an
This is probably a very stupid question, but I am just not sure which
This is probably a very simple question for somebody with experience, but I just
This may be very basic, but I've done a lot of Googling and can't
This question may seem daft (I'm a new to 'programming' and should probably stop
This probably is a dummy question but I cannot find a clear indication. I

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.