xmlreader newline \n instead of \r\n

后端 未结 5 1634
不思量自难忘°
不思量自难忘° 2021-01-11 11:32

When I use XmlReader.ReadOuterXml(), elements are separated by \\n instead of \\r\\n. So, for example, if I have XmlDocument representatino of


<         


        
5条回答
  •  逝去的感伤
    2021-01-11 11:33

    XmlReader will automatically normalize \r\n\ to \n. Although this seems unusual on Windows, it is actually required by the XML Specification (http://www.w3.org/TR/2008/REC-xml-20081126/#sec-line-ends).

    You can do a String.Replace:

    string s = reader.ReadOuterXml().Replace("\n", "\r\n");
    

提交回复
热议问题