Newlines in VB.NET XML Literals

Apparently CR-LF combinations in VB XML literals are silently converted to LF.

Consider the following minimal example:

Module Module1
    Sub Main()
        Dim x As XElement = <xml>1
2</xml>

        ' Print Bytes
        Console.WriteLine(String.Join("-", x.Value.Select(Function(c) AscW(c).ToString("X2"))))
    End Sub
End Module

      

Compiled with Visual Studio 2017 (Framework 4.5.2), this gives

31-0A-32

      

but not

31-0D-0A-32

      

as I expected. I checked the original file with a binary editor and it definitely contains CR-LF (0D-0A) between 1 and 2 in the XML literal.

Is this officially documented behavior or just some implementation details of my compiler that I cannot rely on? If first, where is it documented?

+3


source to share


1 answer


Microsoft adheres to the accepted XML standard to use only line breaks in XML. This concerns interaction with systems other than Windows, which usually only use the feed line. Windows uses CR-LF as its standard, but you'll usually find that only LF works as a line break on Windows.



+5


source







All Articles