开发者

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

开发者 https://www.devze.com 2023-01-16 14:10 出处:网络
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/>.

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 开发者_StackOverflow社区ORM to communicate to the database in order to save it.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消