从数据库中的数据生成 XML 的最佳方法是什么? [英] What is the best way to generate XML from the data in the database?
问题描述
如果我有数千条分层记录要从数据库中获取并生成 xml,那么在具有良好性能和较低 CPU 使用率的情况下最好的方法是什么?
您可以使用
直接从 SQL Server 2005 输出 XMLFOR XML
<块引用>
查询结果作为 XML 文档返回.必须与RAW、AUTO 三种模式之一和显式选项
RAW
<块引用>
结果集中的每一行都是一个带有泛型的 XML 元素标识符作为元素标签
AUTO
<块引用>
结果以简单的形式返回嵌套的 XML 树.一个元素将为每个表字段生成SELECT 子句
明确
<块引用>
指定结果的形状明确的 XML 树.查询必须写在特殊的方式,以便额外的关于嵌套的信息是指定
XMLDATA
<块引用>
返回架构,但不将根元素添加到结果中
元素
<块引用>
指定列是作为子元素返回到表元素.如果未指定,则将它们映射为属性
同时使用
生成内联XSD架构XMLSCHEMA
您可以使用
处理记录中的空值XSINIL
您也可以以二进制形式返回数据.
您可能想查看 MSDN,了解 SQL Server 中的 XML 支持2005,XQuery、XML 数据类型等技术
If I have thousands of hierarchical records to take from database and generate xml, what will be the best way to do it with a good performance and less CPU utilization?
You can output XML directly from SQL Server 2005 using
FOR XML
The results of a query are returned as an XML document. Must be used with one of the three RAW, AUTO and EXPLICIT options
RAW
Each row in the result set is an XML element with a generic identifier as the element tag
AUTO
Results returned in a simple nested XML tree. An element will be generated for each table field in the SELECT clause
EXPLICIT
Specifies the shape of the resulting XML tree explicitly. A query must be written in a particular way so that additional information about the nesting is specified
XMLDATA
Returns the schema, but does not add the root element to the result
ELEMENTS
Specifies that the columns are returned as child elements to the table element. If not specified, they are mapped as attributes
Generate an inline XSD schema at the same time using
XMLSCHEMA
You can handle null values in records using
XSINIL
You can also return data in Binary form.
You might want to have a look on MSDN for XML support in SQL Server 2005, for technologies such as XQuery, XML data type, etc.
这篇关于从数据库中的数据生成 XML 的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!