如何添加xml编码<?xml version="1.0"编码=“UTF-8"?>到 SQL Server 中的 xml 输出

可能是未答复的副本.SQL Server 2008 - 向 XML 输出添加 XML 声明

如果可能,请告诉我.我在一些博客中读到

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 上

See "Limitations of the xml Data Type" on MSDN

将 XML 数据存储在 xml 数据类型实例中时,不会保留 XML 声明 PI,例如 <?xml version='1.0'?>.这是设计使然.数据转换为 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.

相关文章