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

  • Home
  • SEARCH
  • 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 8034939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:10:00+00:00 2026-06-05T02:10:00+00:00

In addition to a list of objects I am serializing to an xml file

  • 0

In addition to a list of objects I am serializing to an xml file using C#’s XmlSerializer, I would like to store a few more independent elements (mainly strings from textboxes) in the same xml.

    public static void SaveBehaviors(ObservableCollection<Param> listParams)
    {
        XmlSerializer _paramsSerializer = new XmlSerializer(listParams.GetType());
        string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
        path += "\\test.xml";
        using (TextWriter writeFileStream = new StreamWriter(path))
        {
            _paramsSerializer.Serialize(writeFileStream, listParams);

            using (XmlWriter writer = XmlWriter.Create(writeFileStream))
            {
                writer.WriteStartElement("Foo"); //test entry...
                writer.WriteAttributeString("Bar", "Some & value");
                writer.WriteElementString("Nested", "data");
                writer.WriteEndElement();
            }
        }
    }

However, deserializing “test.xml” results in an error because of the added element. I suppose writing in the serialized xml file is prohibited and should be avoided?

  • 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-05T02:10:02+00:00Added an answer on June 5, 2026 at 2:10 am

    No. Don’t do that.

    If you need to serialize more than your ObservableCollection, then define a containing type and serialize that.

    public static void SaveBehaviors(ObservableCollection<Param> listParams) 
    { 
        XmlSerializer _paramsSerializer = new XmlSerializer(typeof(ContainingType)); 
        var c = new ContainingType(listParams); 
        c.ExtraInformation = whatever....; 
    
        string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); 
        path += "\\test.xml"; 
        using (TextWriter writeFileStream = new StreamWriter(path)) 
        { 
            _paramsSerializer.Serialize(writeFileStream, c); 
        } 
    } 
    

    Use the XmlSerializer.

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

Sidebar

Related Questions

In addition to this question: iPhone network performance , I would like to know
Extended problem I would like to add a new problem in addition to the
I'm using local shared objects within flash both to store significant amounts of user
To make my code more readable, I like to avoid names of objects that
Is addition(+) operation more complex than comparison operation (>), both in integer as well
I'm new to django. I have 2 simple objects, lets call them - File
I have an entity that, in addition to a few common properties, contains a
Is it legal to have a vector of references to objects, like the following?
In addition to implementing a Bag & List for an assignment, the next step
When building up a list of options in a select list using Javascript I'd

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.