如何在SQL2000的查询中使用XML-Data?
时间:2010-06-18 19:26:00
如何在SQL2000的查询中使用XML-Data?
具体程序如下:
orders.asp
<%@ Language=VBScript %>
<%
Dim sConn
sConn = "Provider=SQLOLEDB; Data Source=(local); Initial Catalog=Northwind; User ID=SA;Password=;"
Dim adoConn
Set adoConn = Server.CreateObject("ADODB.Connection")
adoConn.ConnectionString = sConn
adoConn.CursorLocation = 3 'adUseClient
adoConn.Open
Dim adoCmd
Set adoCmd = CreateObject("ADODB.Command")
Set adoCmd.ActiveConnection = adoConn
adoCmd.CommandText = "Customer[@CompanyName=""Tortuga Restaurante""]"
adoCmd.Dialect = "{ec2a4293-e898-11d2-b1b7-00c04f680c56}"
adoCmd.Properties("Mapping Schema") = "orders.xml"
adoCmd.Properties("Base Path") = "c:\inetpub\wwwroot\chunfeng\"
adoCmd.Properties("Output Stream") = Response
Response.write "<XML ID='MyDataIsle'>"
adoCmd.Execute , , 1024 'adExecuteStream
Response.write "</XML>"
%>
orders.xml
<?xml version="1.0" ?>
<Schema xmlns="urn:schemas-microsoft-com:xml-data" xmlns:dt="urn:schemas-microsoft-com:datatypes"
xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<ElementType name="Order" sql:relation="Orders">
<AttributeType name="CustomerID" />
<AttributeType name="OrderID" />
<AttributeType name="OrderDate" />
<attribute type="CustomerID" sql:field="CustomerID" />
<attribute type="OrderID" sql:field="OrderID" />
<attribute type="OrderDate" sql:field="OrderDate" />
</ElementType>
<ElementType name="Customer" sql:relation="Customers">
<AttributeType name="CustomerID" />
<AttributeType name="CompanyName" />
<attribute type="CustomerID" sql:field="CustomerID" />
<attribute type="CompanyName" sql:field="CompanyName" />
<element type="Order">
<sql:relationship key-relation="Customers" key="CustomerID" foreign-key="CustomerID" foreign-
relation="Orders" />
</element>
</ElementType>
</Schema>
看看运行结果,是不是我们想要的?