Add XML roundtripping documentation for carriage return entities #47034
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
Parsing with
XDocument.Parse()
correctly produces"a\r\nb\nc\r"
, but reserializing with LINQ to XML methods (even withSaveOptions.DisableFormatting
) loses the carriage return entities: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:
XmlWriter
withNewLineHandling.Entitize
XmlWriter
documentationThe documentation now guides users to use:
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.