董晓涛(David Dong)

博客园 首页 新随笔 联系 订阅 管理

In SQL Server 2000, RAW mode FOR XML queries can return only attribute-centric XML. In SQL Server 2005, you can use the ELEMENTS directive with RAW mode queries to return element-centric XML. The following example shows how to use the ELEMENTS directive with RAW mode.

SELECT ProductID, Name, ListPrice
FROM Production.Product
FOR XML RAW, ELEMENTS

 

When element-centric XML is returned in SQL Server 2000, null columns are omitted in the results. In SQL Server 2005, you can specify that null columns should yield empty elements with the xsi:nil attribute by using the XSINIL option with the ELEMENTS directive in AUTO, RAW, and PATH mode queries or by using the elementxsinil column mode in EXPLICIT mode queries. The following examples show how to retrieve empty elements for null values.

-- Using XSINIL with ELEMENTS

SELECT ProductID, Name, Color

FROM Production.Product Product

FOR XML AUTO, ELEMENTS XSINIL

posted on 2005-04-16 08:16  董晓涛  阅读(392)  评论(2编辑  收藏  举报