Why does the carriage return character disappear when converting a string to a SQL Server XML data type?

Whenever I parse a string with an SQL XML data type, I notice that the carriage return disappears when moving spaces and XML carriages. If they are not mixed, everything works fine. Does anyone know why this is happening?

See sample SQL code below

DECLARE @var XML

PRINT 'This is a statement with two XML carriage-return characters'
SET @var = CONVERT (XML,'<root>Dear Sir,&#xD;&#xD;I am passing CR</root>',1)
SELECT @var

PRINT 'output is identical to a statement with two whitespace carriage-return characters'
SET @var = CONVERT (XML,'<root>Dear Sir,

I am passing CR</root>',1)
SELECT @var

PRINT 'Why does this statement only display one space? There is an XML carriage-return AND a whitespace carriage-return character.' 

--Make sure there is no space after &#xD; after you've copied and pasted the code 
SET @var = CONVERT (XML,'<root>Dear Sir,&#xD;
I am passing CR</root>',1)
SELECT @var
+3
source share
1 answer

On Windows, the end of the line is CR-LF. On Unix, end of line is CR.

In the first example, you are using CR-CR. I think SQL Server interprets those that are the end of a Unix-style string and gives two spaces.

Windows, CR-LF-CR-LF. Windows, .

- CR-CR-LF. , -, Windows, CR.

CR-LF &#xD;&#xA;, .

+2

Source: https://habr.com/ru/post/1747326/


All Articles