A var doc = XDocument.Parse("<r>a\r\nb</r>")
and then doc.Root.Value
gives me a\n\b
instead of the expected a\r\nb
. I tried most of the Parse
and Load
overloads, using XmlReader
, Stream
, TextReader
, but didn't manage to load the \r\n
as \r\n
; I always get a \n
. I'm using .NET 6 on Windows.
There is this question about XElement.Load with an answer suggesting to use LoadOptions.PreserveWhitespace
, but this doesn't work for me when using XDocument.Load
or XDocument.Parse
.
How can I load an XML document containing a \r\n
in a value into an XDocument
preserving that \r\n
?