SELECT 1 AS Tag,NULL AS Parent,
CategoryID AS [Category!1!ID!ID],
CategoryName AS [Category!1!Name],
NULL AS [Product!2!ProductID!IDREF],
NULL AS [Product!2!ProductName]
FROM Categories WHERE CategoryID < 3
UNION ALL
SELECT 2 ,1 ,
Categories.CategoryID,
NULL,
ProductID,
ProductName
FROM Categories
JOIN Products ON Categories.CategoryID = Products.CategoryID AND ProductID <5
WHERE Categories.CategoryID < 3
ORDER BY [Category!1!ID!ID] ,[Product!2!ProductID!IDREF]
FOR XML EXPLICIT,XMLDATA
返回结果:
四.使用BINARY BASE64 选项
使用该选项可以检索二进制字段,比如图像数据以base64的形式返回到xml文档。
1.使用RAW方式
查询语句:
SELECT CategoryID,
Picture
FROM Categories
WHERE CategoryID =1
ORDER BY CategoryID DESC
FOR XML RAW,BINARY BASE64
返回结果:
2.使用AUTO方式
查询语句:
SELECT CategoryID,
Picture
FROM Categories
WHERE CategoryID =2
ORDER BY CategoryID DESC
FOR XML AUTO,BINARY BASE64
返回结果:
查询语句:
SELECT CategoryID,
Picture
FROM Categories
WHERE CategoryID =1
ORDER BY CategoryID DESC
FOR XML AUTO,ELEMENTS,BINARY BASE64
返回结果:
1
FRwvAAIAAAANAA4AFAAhAP////9CaXRt...
文章来源于领测软件测试网 https://www.ltesting.net/