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

  • Home
  • SEARCH
  • 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 7892401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:51:37+00:00 2026-06-03T06:51:37+00:00

T-SQL XML value loses new line formats I have XML file loaded into SQL

  • 0

T-SQL XML value loses new line formats

I have XML file loaded into SQL server. I query this file to extract the nodes with value.

The problem is the new line characters are lost while selection. How to retain formatting so that when I display the text on the web, it not appear messy without line breaks.

See text and screenshots for details

enter image description here

Editor shows that new lines \n are lost

T-SQL code:

declare @Text xml ;
set @Text= '<?xml version="1.0" encoding="utf-8"?>
<topic>
  <L1>
    <Subject>Subject text</Subject>
    <Details>
      Story Details are

      This is paragraph

      Text after After two line breaks

      Text after After two line breaks

    </Details>
  </L1>
</topic>'

;with t as (select @Text [xmlcolumn])
--select * from t
SELECT  x.a.value('(Subject)[1]','nvarchar(max)') as [Subject]
,       x.a.value('(Details)[1]','nvarchar(max)') as [Details]
FROM   t
cross apply
t.xmlcolumn.nodes('//L1') x(a)
  • 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-06-03T06:51:39+00:00Added an answer on June 3, 2026 at 6:51 am

    Update: I misread your question – the problem with the newlines is purely in SQL Server Management Studio – it cannot represent those newlines. When you read your XML from an application in C# or VB.NET, those newlines will still be there – trust me.

    But this original answer might also be relevant in other cases – you need to be aware that SQL Server is not storing your XML “as is” – it parses and converts it. So when you ask to get it back, it might look slightly different, but it’s still the same XML functionally.


    Yes, this is normal, expected behavior.

    SQL Server stores your XML in a tokenized format – e.g. it doesn’t store the actual, textual representation of your XML, but it parses and tokenizes your XML into XML fragments that are then stores inside this XML datatype.

    Therefore, when you query it again, you’ll get back a semantically correct and identical representation – but there’s a possibility that certain textual representations are different.

    E.g. when you pass in an empty XML element something like this:

    <MyEmptyElement></MyEmptyElement>
    

    you’ll get back the “short” form of that when you retrieve the XML from SQL Server again:

    <MyEmptyElement />
    

    This is not the exact same text – but it’s 100% the same XML from a semantic perspective.

    As far as I know, you cannot influence this behavior in any way – you’ll just have to live with it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this XML in SQL Server <data> <add key=images value=image/path/img.gif /> <data> I
In Microsoft SQL Server 2008, when executing .query('{xpath}/text()') on an XML stream column value,
Cannot dump Stack Overflow XML file into SQL Server 2008. Could you please explain
I have an XML value and an XPath query like this: XML: <Firms> <Firm
I have to load a xml into a sql server table. The xml size
I have this sql script DECLARE @XmlStr XML SET @XmlStr = '<EmployeeID> <Employee>48f9194f-8d46-e111-8849-0050569445f1</Employee> <Employee>7d725561-8d46-e111-8849-0050569445f2</Employee>
This is a follow up question to T-Sql xml query If I add a
I have a XML structure in a XML column on a SQL Server table
I have some xml and need to extract values using sql <?xml version=1.0 ?>
Assuming I have a SQL Server 2005 table with an xml column containing the

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.