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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:34:26+00:00 2026-06-15T19:34:26+00:00

Possible Duplicate: XML Carriage return encoding I have a class with some simple string

  • 0

Possible Duplicate:
XML Carriage return encoding

I have a class with some simple string and int values on it that I am using the XmlSerializer to serialize to a file like so. (this is literally the code I am using)

XmlSerializer xmlser = new XmlSerializer(typeof(NPC));
using (Stream st = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None)) 
{
    xmlser.Serialize(st, npc);
}

That all works fine; I have verified that upon serialization, the correct data is in the file in the <Other></Other> element, complete with \r\n, if I entered such in the file. The problem comes upon deserialization (again; literally the code I am using, except for the ‘test’ result upon failure)

XmlSerializer xmlser = new XmlSerializer(typeof(NPC));
NPC npc = null;
using (Stream st = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.None)) 
{
    npc = (NPC)xmlser.Deserialize(st);
}
//Testing...
if(!npc.Other.Contains("\r\n")) 
{
    //this always occurs, even when the <Other></Other> item DOES have CR-LF
}

Immediately upon deserialization, string properties on the object which had \r\n values will have them replaced by \n alone. I have verified even after deserializing that the file reflects \r\n in the proper elements, and I am doing nothing else with the npc object before testing that the \r are removed.

NPC is a simple class, defined like so:

[Serializable]
public class NPC
{
    public int Field1{get; set;}
    public string Other {get; set;}
    public int Etc... {get; set;}
}

So; why is my Other property losing its \r from its \r\n upon deserialization?

  • 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-15T19:34:27+00:00Added an answer on June 15, 2026 at 7:34 pm

    Here is a link you can look at:
    XML Carriage return encoding

    If you google “XML Carriage Return” you will come up with many many other links to people with the same problem.

    It would appear that this is by design.

    This is because compliant XML parsers must, before parsing, translate CRLF and any CR not followed by a LF to a single LF. This behavior is defined in the End-of-Line handling section of the XML 1.0 specification.

    To preserve your newlines, you’ll have to do some encoding, or simply change all of your \n back to \r after deserialization

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

Sidebar

Related Questions

Possible Duplicate: How to Deserialize XML document Suppose that I have a class that
Possible Duplicate: Converting XML to JSON using Python? I'm doing some work on App
Possible Duplicate: A simple program to CRUD node and node values of xml file
Possible Duplicate: Creating a simple XML file using python I want to write a
Possible Duplicate: Best practices to parse xml files? I have a xml string: <XML>
Possible Duplicate: Silverlight XML editor / syntax highlighting Hello, I have some XML in
Possible Duplicate: Parse XML Elements with LINQ I have an XML document that looks
Possible Duplicate: LINQ to XML. How to get some string? My XML Response look
Possible Duplicate: How to get values of xml elements? I have the following data
Possible Duplicate: Best XML Parser for PHP I have a string with XML data

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.