It appears that SQL Server removes the \r
characters when parsing XML. So when my stored procedure gets the values ββin xml to save, all line breaks are represented as \n
instead of \r\n.
Is there a way to force SQL Server not to remove \r
characters? In the example Node1
below, the value does not contain \r
characters.
DECLARE @hDoc int DECLARE @Xml nvarchar(MAX) SET @Xml = N'<Root><Node1><![CDATA[' + nchar(13) + nchar(10) + N'Some ' + nchar(13) + nchar(10) + N' Value]]></Node1></Root>' EXEC sp_xml_preparedocument @hDoc OUTPUT, @Xml SELECT Node1 ,convert(varbinary(max),Node1)
Output:
@PJB suggested XQuery nodes instead. But that does not help. I tried to execute the request below and got the same result.
DECLARE @xml xml SET @xml = convert(xml, N'<Root><Node1><![CDATA[' + nchar(13) + nchar(10) + N'Some ' + nchar(13) + nchar(10) + N' Value]]></Node1></Root>') declare @Node1 nvarchar(30) select @Node1 = node.value('.', 'nvarchar(30)') from @xml.nodes('/Root/Node1') as doc(node) SELECT @Node1 ,convert(varbinary(max),@Node1)
source share