Skip to content

Add XML roundtripping documentation for carriage return entities #47034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 30, 2025

The LINQ to XML whitespace preservation documentation was missing crucial information about XML roundtripping with carriage return entities. Users encountering XML with 
 entities would find that LINQ to XML's standard serialization doesn't preserve them, breaking roundtrip scenarios.

Problem

When XML contains carriage return entities like this:

<x xml:space="preserve">a&#xD;
b
c&#xD;</x>

Parsing with XDocument.Parse() correctly produces "a\r\nb\nc\r", but reserializing with LINQ to XML methods (even with SaveOptions.DisableFormatting) loses the carriage return entities:

<x xml:space="preserve">a
b
c</x>

Upon reparsing, the value becomes "a\nb\nc\n" - different from the original.

Solution

Added a new section "Roundtripping XML with carriage return entities" that:

  • Explains the difference between LINQ to XML whitespace preservation and true XML roundtripping
  • Demonstrates the issue with practical code examples
  • Provides the solution using XmlWriter with NewLineHandling.Entitize
  • Shows complete working code that preserves carriage return entities
  • Links to relevant XmlWriter documentation

The documentation now guides users to use:

XmlWriterSettings settings = new XmlWriterSettings
{
    NewLineHandling = NewLineHandling.Entitize,
    OmitXmlDeclaration = true
};

This enhancement provides the missing guidance requested in the original issue while maintaining consistency with existing documentation style and following the Microsoft Writing Style Guide.

Fixes #9680.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Missing discussion on how to roundtrip XML with carriage return entities Add XML roundtripping documentation for carriage return entities Jun 30, 2025
@Copilot Copilot AI requested a review from BillWagner June 30, 2025 20:03
Copilot finished work on behalf of BillWagner June 30, 2025 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing discussion on how to roundtrip XML with carriage return entities
2 participants