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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:03:03+00:00 2026-05-29T21:03:03+00:00

I am serializing a string from a multiline text box to an XML. Is

  • 0

I am serializing a string from a multiline text box to an XML. Is send the line breaks and tabs to save in the XML so when I deserialize it, I get it back looking the same?

Example – The textbox will look like:

Hello JohnDoe,

     This is a message
...
Somelines....

Thank you,
...
End

When I serialize this and then deserialize it, the textbox gets populated like:

Hello JohnDoe,This is a message..Some lines....Thank you,...End

It doesn’t have to be really pretty, I’m just trying to come up with a good way to get it back in a better format. Thanks.

Okay so the code i have is as follows:

public void SerializeToXML(List<Report> newReport)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(List<Report>));

            //XmlWriterSettings serializer_settings = new XmlWriterSettings();
            //serializer_settings.Indent = true;
            //serializer_settings.NewLineOnAttributes = true;

            TextWriter textWriter = new StreamWriter(xmlPath);
            serializer.Serialize(textWriter, newReport);
            textWriter.Close();
        }

Where Report is just a class with some string attributes. The commented lines are somethings I was trying to accomplish my goal.

Report class code:

public class Report
    {
        public string name
        { get; set; }

        public string email
        { get; set; }

        public string defectID
        { get; set; }

        public string fixedBuild
        { get; set; }

        public string description
        { get; set; }

        [XmlIgnore]
        public string messageBody
        { get; set; }

     private static readonly XmlDocument _xmlDoc = new XmlDocument();

     [XmlElement("messageBody")]
     public XmlCDataSection TextCData
     {
         get
         {
             return _xmlDoc.CreateCDataSection(messageBody);
         }
         set
         {
             messageBody = value.Data;
         }
     }
    }

the output remains the same (no whitespace formatting).

  • 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-29T21:03:03+00:00Added an answer on May 29, 2026 at 9:03 pm

    One way to preserve all whitespace in your XML is to use a CDATA section. The details depend on the way you do your serialization. See this question for an explanation in a web service context. If you serialize manually, use XmlWriter.WriteCData method.

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

Sidebar

Related Questions

I'm serializing to XML my class where one of properties has type List<string>. public
I'm writing classes which (de)serialize to/from XML. When serializing and deserializing, the class gets
I am serializing some C structure to string and than deserializing it with strtok()
I am serializing to a json object using: public static string ToJson(this object obj)
Right now, I'm currently serializing a class like this: class Session { String setting1;
I'm serializing class which contains DateTime property. public DateTime? Delivered { get; set; }
I am serializing a class using simple-xml ( http://simple.sourceforge.net/ ) but when i try
I'm trying to create a class that will contain functions for serializing/deserializing objects to/from
I'm getting an error with serializing a char* string error C2228: left of '.serialize'
I have a simple class derived from a generic list of string as follows:

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.