XmlReaders return XML 声明吗?
Do XmlReaders return XML Declarations?
我正在尝试创建一个 SQLCLR 标量函数来解析 nvarchar(max) 字符串和 returns XML。数据总是作为没有 xml 声明的片段返回,而不是完整的文档。相关代码是-
XmlDocument doc = new XmlDocument( );
XmlDeclaration xDec = doc.CreateXmlDeclaration( "1.0", "UTF-8", null );
doc.AppendChild(xDec);
XmlElement rootnode = doc.CreateElement("Root Node");
doc.AppendChild(rootnode);
... snipped ...
XmlReader xread = new XmlNodeReader(doc);
XmlReaderSettings xsetRead = new XmlReaderSettings();
xsetRead.ConformanceLevel = System.Xml.ConformanceLevel.Document;
return new SqlXml(XmlReader.Create(xread,xsetRead));
我无法确定我是否滥用了 XmlReader 或者这是 SQLCLR 环境的结果。我在 SQL 查询中唯一可以返回的是根节点及其子节点。
Limitations of the xml Data Type
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. All other PIs in the XML instance are preserved.
XML Data Type and Columns (SQL Server)
The data is stored in an internal representation that preserves the XML content of the data. This internal representation includes information about the containment hierarchy, document order, and element and attribute values. Specifically, the InfoSet content of the XML data is preserved. For more information about InfoSet, visit http://www.w3.org/TR/xml-infoset. The InfoSet content may not be an identical copy of the text XML, because the following information is not retained: insignificant white spaces, order of attributes, namespace prefixes, and XML declaration.
我正在尝试创建一个 SQLCLR 标量函数来解析 nvarchar(max) 字符串和 returns XML。数据总是作为没有 xml 声明的片段返回,而不是完整的文档。相关代码是-
XmlDocument doc = new XmlDocument( );
XmlDeclaration xDec = doc.CreateXmlDeclaration( "1.0", "UTF-8", null );
doc.AppendChild(xDec);
XmlElement rootnode = doc.CreateElement("Root Node");
doc.AppendChild(rootnode);
... snipped ...
XmlReader xread = new XmlNodeReader(doc);
XmlReaderSettings xsetRead = new XmlReaderSettings();
xsetRead.ConformanceLevel = System.Xml.ConformanceLevel.Document;
return new SqlXml(XmlReader.Create(xread,xsetRead));
我无法确定我是否滥用了 XmlReader 或者这是 SQLCLR 环境的结果。我在 SQL 查询中唯一可以返回的是根节点及其子节点。
Limitations of the xml Data Type
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. All other PIs in the XML instance are preserved.
XML Data Type and Columns (SQL Server)
The data is stored in an internal representation that preserves the XML content of the data. This internal representation includes information about the containment hierarchy, document order, and element and attribute values. Specifically, the InfoSet content of the XML data is preserved. For more information about InfoSet, visit http://www.w3.org/TR/xml-infoset. The InfoSet content may not be an identical copy of the text XML, because the following information is not retained: insignificant white spaces, order of attributes, namespace prefixes, and XML declaration.