DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> XML學習教程 >> XML詳解 >> 使用模板執行SQL查詢
使用模板執行SQL查詢
編輯:XML詳解     

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>


XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved