<attribute type="ProductID" />
<attribute type="UnitPrice"/>
<attribute type="Quantity" />
<element type="Discount" sql:field="Discount"/>
</ElementType>
<ElementType name="Discount" dt:type="string"
sql:relation="[Order Details]"/>
<ElementType name="Employee" sql:relation="Employees">
<AttributeType name="EmployeeID" dt:type="idref"
sql:id-prefix="Emp-" />
<AttributeType name="LastName" />
<AttributeType name="FirstName" />
<AttributeType name="Title" />
<attribute type="EmployeeID"/>
<attribute type="LastName" />
<attribute type="FirstName" />
<attribute type="Title" />
</ElementType>
</Schema>
假如您想深入了解架构文件的话,请参看SQL Server 2000的用户文档或等待我的以后的文章。
和内嵌在XML模板文件中的SQL查询语句一样,XPath查询语句使用urn:schemas-microsoft-com:xml-sql和sql作为前缀,共同标示用在模板中的自定义元素和属性,对于XPath查询而言,我们使用一个名为xpath-query的元素来标识查询语法,这个元素也有一个名为mapping-schema的属性,用来标示相应用以映射表和字段到特定的XML项目的架构文件所在的路径。
下面的代码给出了另一个使用更复杂XPath查询的模板文件。
<Northwind xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<sql:xpath-query mapping-schema="listing4.xdr">
/Customer[@CustomerID='ALFKI']/Order/
Employee[@LastName='Suyama']
</sql:xpath-query>
</Northwind>
当执行这个模板文件时,XPath查询返回与某个客户签下订单的雇员(employee)的姓名,结果如下:
<Northwind xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<Employee EmployeeID="Emp-6" LastName="Suyama" FirstName="Michael"Title="Sales Representative"/>
</Northwind>
模板文件中使用的XPath查询也可以使用参数,处理过程很象在XSL样式表中使用参数一样。象XSL一样,使用$指定一个变量。下面的代码说明了如何在一个包含XPath查询的模板文件中整合变量。
<Northwind xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<sql:header>
<sql:param name="ID"/>
</sql:header>
<sql:xpath-query mapping-schema="listing4.xdr"> {{should this be "listing6.xdr"?}}
/Customer/Order[@OrderID=$ID]
</sql:xpath-query>
</Northwind>
通过在URL中传递参数名和相应的参数值,我们就可以完成把参数传递到模板中的操作。结果如下:
<Northwind xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<Order OrderID="Ord-10643" EmployeeID="6" OrderDate="1997-08-25T00:00:00" RequiredDate="1997-09-22T00:00:00" ShippedDate=
"1997-09-02T00:00:00">
评论加载中…
![]() |