Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6891707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:26:38+00:00 2026-05-27T06:26:38+00:00

It looks like SQL Server removes \r characters when parsing XML. So when my

  • 0

It looks like SQL Server removes \r characters when parsing XML. So when my stored procedure receives values in xml for saving, all line breaks are represented as \n instead of \r\n.

Is there any way I can force SQL Server to not remove \r characters? In the sample below Node1 value doesn’t contain \r symbols.


    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) -- Contains 0A00 in the start instead of 0D0A,
        ,charindex(nchar(13),Node1)
    FROM
        OPENXML(@hDoc, N'/Root', 2) WITH (Node1 NVARCHAR(MAX))

    EXEC sp_xml_removedocument @hDoc

Output:
enter image description here

@PJB suggested to use XQuery nodes instead. But this doesn’t helps. I tried to run query 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) -- Contains 0A00 in the start instead of 0D0A,
        ,charindex(nchar(13),@Node1)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:26:39+00:00Added an answer on May 27, 2026 at 6:26 am

    Carriage return symbol is removed from XML

    This is the correct behavior according the XML spec on End-of-Line Handling.

    the XML processor MUST behave as if it normalized all line breaks in
    external parsed entities (including the document entity) on input,
    before parsing, by translating both the two-character sequence #xD #xA
    and any #xD that is not followed by #xA to a single #xA character.

    You could try to use a replace to get the carriage-return back.

    select @Node1 = replace(node.value('.', 'nvarchar(30)'), nchar(10), nchar(13)+nchar(10))
    from @xml.nodes('/Root/Node1') as doc(node)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On SQL Server 2005, I have a complex multi-level allocation process which looks like
I've got a SQL statement in SQL Server 2005 that looks something like this:
I'm using SQL Server 2008. I have a database table that looks like this
for SQL Server 2008 R2 I have a resultset that looks like this (note
I have been writing a user-defined function in SQL Server: It looks like this
I have a SQL Server 2000 stored procedure that accepts a number of input
My Table 'Levels' in a SQL Server 2005 database looks like this: LevelId Description
I'm using SQL Server 2005. The query would look like this Select col1, col2,
I have a query in Delphi using DBExpress TSQLQuery that looks like so ActiveSQL.sql.add('SELECT
I have SQL data that looks like this: events id name capacity 1 Cooking

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.