I am having issues while inserting XML into XML column in table using SQL Server 2008.
I insert
<test></test>
and SQL Server column stores it as:
<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. In it’s original form.
We have been using DB2 for years and DB2 does not alter your inserted XML.
So my question is… Is it possible to disable XML optimization on XML columns in SQL Server 2008?
SQL Server will store a semantically correct representation of your XML in an optimized form; 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).
But you cannot enforce an identical representation to be rendered out again from the
XMLcolumn – SQL Server will render out what it considered the optimal string representation of your XML content.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)