gpt4 book ai didi

c# - XmlReaders 是否返回 XML 声明?

转载 作者:太空宇宙 更新时间:2023-11-03 15:43:51 27 4
gpt4 key购买 nike

我正在尝试创建一个解析 nvarchar(max) 字符串并返回 XML 的 SQLCLR 标量函数。数据总是作为没有 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.

关于c# - XmlReaders 是否返回 XML 声明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29109141/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com