如何添加XML编码<?xml version ="1.0" encoding ="UTF-8"?到SQL Server中的xml输出
可能是未回答的重复项. SQL Server 2008-向XML输出添加XML声明
Probably a duplicate of unanswered. SQL Server 2008 - Add XML Declaration to XML Output
如果可以的话,请告诉我.我在一些博客中阅读
Please let me know if this is possible. I read in some blogs
http://forums.asp.net/t/1455808.aspx/1
http://www.devnewsgroups.net/group/microsoft.public.sqlserver.xml/topic60022.aspx
但是我不明白为什么我不能这样做.
But I couldn't understand why I can't do this.
您必须手动添加它. SQL Server始终将xml内部存储为ucs-2,因此SQL不可能生成utf-8编码标头
You have to add it manually. SQL Server always stores xml internally as ucs-2 so it is impossible for SQL to generate it a utf-8 encoding header
请参见"xml数据类型的限制" 在MSDN上
在XML数据类型实例中存储XML数据时,不会保留XML声明PI,例如
<?xml version='1.0'?>
.这是设计使然.将数据转换为xml类型后,XML声明(<?xml ... ?>
)及其属性(版本/编码/独立)丢失. XML声明被视为XML解析器的指令. XML数据在内部存储为ucs-2.
The XML declaration PI, for example,
<?xml version='1.0'?>
, is not preserved when storing XML data in an xml data type instance. This is by design. The XML declaration (<?xml ... ?>
) and its attributes (version/encoding/stand-alone) are lost after data is converted to type xml. The XML declaration is treated as a directive to the XML parser. The XML data is stored internally as ucs-2.