gpt4 book ai didi

c# - 为什么 XElement 值属性更改\r\n 为\n?

转载 作者:数据小太阳 更新时间:2023-10-29 02:13:20 25 4
gpt4 key购买 nike

我对 XElement 有一个奇怪的行为。似乎 Value 属性将换行表达式\r\n 更改为类似 unix 的表达式\n。这是为什么?

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

谢谢!

最佳答案

我相信这是设计使然 - XML 将新行存储为 LF,而不是 Windows CR+LF。

如果您考虑一下,它与 XML 不保留白色字符的原则是一致的,除非您有 xml:space="preserve"。尝试将其添加为节点属性,看看您会得到什么。

关于c# - 为什么 XElement 值属性更改\r\n 为\n?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4220243/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com