深入探讨SQL Server 2000对XML的支持
2008-09-09 10:03:09 来源:WEB开发网四、XPath查询 架构和模板
XPath查询也可以被内嵌进一个XML模板文件中,下面的代码是一个包含XPath查询的简单的XML模板文件。
<Northwind xmlns:sql=
"urn:schemas-microsoft-com:
xml-sql">
<sql:xpath-query mapping-schema=
"file4.xdr">
/Customer[@CustomerID=
'ALFKI']/Order
</sql:xpath-query>
</Northwind>
这个查询使用了一个架构(schema)返回CustomerID号为ALFKI的用户的所有的订单,如果想要使XPath语句运行,必须使用一个XDR架构文件映射不同的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="Customer" sql:relation="Customers">
<AttributeType name="CustomerID" dt:type="id" />
<AttributeType name="CompanyName" />
<AttributeType name="ContactName" />
<AttributeType name="City" />
<AttributeType name="Fax" />
<AttributeType name="Orders" dt:type=
"idrefs" sql:id-prefix="Ord-" />
<attribute type="CustomerID" />
<attribute type="CompanyName" />
<attribute type="ContactName" />
<attribute type="City" />
<attribute type="Fax" />
<attribute type="Orders" sql:relation=
"Orders" sql:field="OrderID">
<sql:relationship
key-relation="Customers"
key="CustomerID"
foreign-relation="Orders"
foreign-key="CustomerID" />
</attribute>
<element type="Order">
<sql:relationship
key-relation="Customers"
key="CustomerID"
foreign-relation="Orders"
foreign-key="CustomerID" />
</element>
</ElementType>
<ElementType name="Order" sql:relation="Orders">
<AttributeType name="OrderID" dt:type=
"id" sql:id-prefix="Ord-" />
<AttributeType name="EmployeeID" />
<AttributeType name="OrderDate" />
<AttributeType name="RequiredDate" />
<AttributeType name="ShippedDate" />
<attribute type="OrderID" />
<attribute type="EmployeeID" />
<attribute type="OrderDate" />
<attribute type="RequiredDate" />
<attribute type="ShippedDate" />
<element type="OrderDetail">
<sql:relationship
key-relation="Orders"
key="OrderID"
foreign-relation="[Order Details]"
foreign-key="OrderID" />
</element>
<element type="Employee">
<sql:relationship
key-relation="Orders"
key="EmployeeID"
foreign-relation="Employees"
foreign-key="EmployeeID" />
</element>
</ElementType>
<ElementType name="OrderDetail" sql:relation=
"[Order Details]"
sql:key-fields="OrderID ProductID">
<AttributeType name="ProductID" dt:type="idref"
sql:id-prefix="Prod-" />
<AttributeType name="UnitPrice"/>
<AttributeType name="Quantity" />
<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的用户文档或等待我的以后的文章。
- ››sql server自动生成批量执行SQL脚本的批处理
- ››sql server 2008亿万数据性能优化
- ››SQL Server 2008清空数据库日志方法
- ››sqlserver安装和简单的使用
- ››SQL Sever 2008 R2 数据库管理
- ››SQL SERVER无法安装成功,sqlstp.log文件提示[未发...
- ››Sql Server中通过父记录查找出所有关联的子记录
- ››SqlServer触发器、存储过程和函数
- ››SQL Server 中的事务(含义,属性,管理)
- ››Sqlite数据库插入和读取图片数据
- ››Sql server 2005拒绝了对对象 'xx表' (数...
- ››Sql server 2005拒绝了对对象 'xx表' (数...
更多精彩
赞助商链接