Why does the XElement Value property change \ r \ n to \ n?

I have weird behavior with XElement. The Value property seems to change the new expression of the string \ r \ n to a unix-like expression \ n. Why is this?

string valueString = "abc\r\ndef"; string xmlString = "<desc>abc\r\ndef</desc>"; XElement xElement = XElement.Parse(xmlString); string toString = xElement.ToString(); //as expected same value as xmlString string xElementValue = xElement.Value; //contains abc\ndef instead of abc\r\ndef 

Thanks!

+4
source share
1 answer

I believe this is by design - XML ​​saves the new line as LF, not as Windows CR + LF.

If you think about it, this is consistent with the principle that XML does not preserve white characters unless you have xml:space="preserve" . Try adding this as a node attribute and see what you get.

+1
source

All Articles