简体   繁体   English

插入时SQL Server 2008 XML的更改

[英]SQL Server 2008 XML changes on insert

I am having issues while inserting XML into XML column in table using SQL Server 2008. 使用SQL Server 2008将XML插入表的XML列时遇到问题。

I insert 我插入

<test></test>

and SQL Server column stores it as: SQL Server列将其存储为:

<test />

Now, I know that the latest form is actually the correct one and that the first form is not really a correct XML syntax, but I have to keep XML as it was passed in with import from customer. 现在,我知道最新的形式实际上是正确的形式,而第一种形式并不是真正的正确XML语法,但是我必须保留XML,因为它是从客户导入时传入的。 In it's original form. 以其原始形式。

We have been using DB2 for years and DB2 does not alter your inserted XML. 我们已经使用DB2多年了,DB2不会更改您插入的XML。

So my question is... Is it possible to disable XML optimization on XML columns in SQL Server 2008? 所以我的问题是...是否可以在SQL Server 2008中对XML列禁用XML优化?

SQL Server will store a semantically correct representation of your XML in an optimized form; SQL Server将以一种优化的形式存储XML的语义正确表示。 it's not the actual string that you input that gets stored (it's parsed into XML "fragments" and those are stored in an optimized way). 存储的不是您输入的实际字符串(它被解析为XML“片段”,并且以优化的方式存储)。

But you cannot enforce an identical representation to be rendered out again from the XML column - SQL Server will render out what it considered the optimal string representation of your XML content. 但是您不能强制将相同的表示形式再次从XML列中呈现出来-SQL Server将呈现它认为是XML内容的最佳字符串表示形式的内容。

If you really need to have a 100% identical representation, then you need to store your XML as a string column ( (n)varchar(x) - or (n)varchar(max) if you need more than 8000 bytes of storage) 如果确实需要100%相同的表示形式,则需要将XML存储为字符串列(如果需要超过8000个字节的存储,则为(n)varchar(x) -或(n)varchar(max)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM