A、創建包含簡單Select語句的模板文件。
<?XML version="1.0" encoding="UTF-8"?>
<root xmlns:sql="urn:schemas-microsoft-com:XML-sql">
<sql:query>
select top 10 customerid,companyname from customers for XML auto
</sql:query>
</root>
該模板在文件(temp.XML)中並通過URL執行:http://localhost/template/temp.XML,結果如下:
<?XML version="1.0" encoding="UTF-8" ?>
-<root xmlns:sql="urn:schemas-microsoft-com:XML-sql">
<customers customerid="ALFKI" companyname="Alfreds Futterkiste" />
<customers customerid="ANATR" companyname="Ana Trujillo Emparedados y helaDOS" /> <customers customerid="ANTON" companyname="Antonio Moreno Taquería" />
<customers customerid="AROUT" companyname="Around the Horn" />
</root>
B、在模板文件中執行存儲過程。
在SQL Server建一存儲過程CategoryInfo:
if exists (select name from sysobjects where
name="CategoryInfo" and type="P"
Drop procedure CategoryInfo
GO
CREATE PROCEDURE dbo.CategoryInfo
AS
Select CategoryID,CategoryName from CategorIEs where
CategorIEs.CategoryID=2 for XML Auto
該模板存儲在文件(temp1.XML)中並通過URL執行:http://localhost/template/temp1.XML,結果如下:
<?XML version="1.0" encoding="UTF-8" ?>
-<root xmlns:sql="urn:schemas-microsoft-com:XML-sql">
<CategorIEs CategoryID="2" CategoryName="Condiments"/>
</root>