Michael
Michael

Reputation: 210

How do I save xml exactly as is to a xml database field?

At the moment, if I save <element></element> to a SQL Server 2008 database in a field of type xml, it converts it to <element/>.

How can I preserve the xml empty text as is when saving?

In case this is a gotcha, I am utilising Linq to Sql as my ORM to communicate to the database in order to save it.

Upvotes: 2

Views: 184

Answers (1)

Jon Seigel
Jon Seigel

Reputation: 12401

What you're asking for is not possible.

SQL Server stores data in xml columns as a binary representation, so any extraneous formatting is discarded, as you found out.

To preserve the formatting, you would have to store the content in a text field of type varchar(MAX) or nvarchar(MAX). Hopefully you don't have to run XML-based queries on the data.

http://msdn.microsoft.com/en-us/library/ms189887.aspx

Upvotes: 2

Related Questions