以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XML基础 』  (http://bbs.xml.org.cn/list.asp?boardid=1)
----  请教一个XQUERY的问题  (http://bbs.xml.org.cn/dispbbs.asp?boardid=1&rootid=&id=51515)


--  作者:templarkk
--  发布时间:8/19/2007 8:55:00 AM

--  请教一个XQUERY的问题
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2007 rel. 3 (http://www.altova.com) by templar (EMBRACE) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
 <!-- Declaration -->

 <xs:element name="FlightDetails">
  <xs:annotation>
   <xs:documentation>GoodTravel Company Flight Details XML Database</xs:documentation>
  </xs:annotation>
  <xs:complexType>
   <xs:sequence>
    <xs:element name="CLIENT" type="C_TYPE" minOccurs="0" maxOccurs="unbounded"/>
    <xs:element name="FLIGHT" type="F_TYPE" minOccurs="0" maxOccurs="unbounded"/>
    <xs:element name="BOOKING" type="B_TYPE" minOccurs="0" maxOccurs="unbounded"/>
   </xs:sequence>
  </xs:complexType>
  <xs:key name="clientkey">
   <xs:selector xpath="FlightDetails/CLIENT"/>
   <xs:field xpath="clientID"/>
  </xs:key>
  <xs:key name="flightkey">
   <xs:selector xpath="FlightDetails/FLIGHT"/>
   <xs:field xpath="flightID"/>
  </xs:key>
  <xs:key name="bookingkey">
   <xs:selector xpath="FlightDetails/BOOKING"/>
   <xs:field xpath="clientID"/>
   <xs:field xpath="flightID"/>
  </xs:key>
  <xs:keyref name="bookingkeyref1" refer="clientkey">
   <xs:selector xpath="FlightDetails/BOOKING"/>
   <xs:field xpath="clientID"/>
  </xs:keyref>
  <xs:keyref name="bookingkeyref2" refer="flightkey">
   <xs:selector xpath="FlightDetails/BOOKING"/>
   <xs:field xpath="flightID"/>
  </xs:keyref>
  <xs:unique name="clientIDunique">
   <xs:selector xpath="FlightDetails/CLIENT"/>
   <xs:field xpath="clientID"/>
  </xs:unique>
  <xs:unique name="flightIDunique">
   <xs:selector xpath="FlightDetails/FLIGHT"/>
   <xs:field xpath="flightID"/>
  </xs:unique>
 </xs:element>
 <!-- Definition of table types -->
 <xs:complexType name="C_TYPE">
  <xs:sequence>
   <xs:element ref="clientID"/>
   <xs:element name="name" type="nametype"/>
   <xs:element name="address" type="addresstype"/>
   <xs:element name="phone" type="phonetype"/>
  </xs:sequence>
 </xs:complexType>
 <xs:complexType name="F_TYPE">
  <xs:sequence>
   <xs:element ref="flightID"/>
   <xs:element name="depDate" type="xs:date"/>
   <xs:element name="depTime" type="xs:time"/>
   <xs:element name="arrDate" type="xs:date"/>
   <xs:element name="arrTime" type="xs:time"/>
   <xs:element name="origin" type="nametype"/>
   <xs:element name="destination" type="nametype"/>
  </xs:sequence>
 </xs:complexType>
 <xs:complexType name="B_TYPE">
  <xs:sequence>
   <xs:element ref="flightID"/>
   <xs:element ref="clientID"/>
   <xs:element name="class" type="classtype"/>
  </xs:sequence>
 </xs:complexType>
 <!-- Definition of reference elements -->
 <xs:element name="clientID" type="clientIDtype"/>
 <xs:element name="flightID" type="flightIDtype"/>
 <!-- Definition of other types -->
 <xs:simpleType name="clientIDtype">
  <xs:restriction base="xs:string">
   <xs:minLength value="6"/>
   <xs:maxLength value="6"/>
   <xs:pattern value="[0-9]{6}"/>
  </xs:restriction>
 </xs:simpleType>
 <xs:simpleType name="flightIDtype">
  <xs:restriction base="xs:string">
   <xs:minLength value="5"/>
   <xs:maxLength value="5"/>
   <xs:pattern value="[A-Z]{2}[0-9]{3}"/>
  </xs:restriction>
 </xs:simpleType>
 <xs:simpleType name="nametype">
  <xs:restriction base="xs:string">
   <xs:maxLength value="20"/>
  </xs:restriction>
 </xs:simpleType>
 <xs:simpleType name="addresstype">
  <xs:restriction base="xs:string">
   <xs:maxLength value="50"/>
  </xs:restriction>
 </xs:simpleType>
 <xs:simpleType name="phonetype">
  <xs:restriction base="xs:string">
   <xs:maxLength value="12"/>
  </xs:restriction>
 </xs:simpleType>
 <xs:simpleType name="classtype">
  <xs:restriction base="xs:string">
   <xs:enumeration value="first"/>
   <xs:enumeration value="business"/>
   <xs:enumeration value="economy"/>
  </xs:restriction>
 </xs:simpleType>
</xs:schema>


此为.xsd文件   要想用xquery查询:
列出destination为Sydney class为economy 的flightID和client name
试了很久都不成功。。。  如果用SQL 一个内连接就搞定了。。
用XQUERY怎查询呀。。  
望高手帮忙。。。。


--  作者:templarkk
--  发布时间:8/19/2007 8:56:00 AM

--  
并附上XML文件

<?xml version="1.0" encoding="UTF-8"?>
<!--Sample XML file generated by XMLSpy (http://www.altova.com)-->
<FlightDetails xsi:noNamespaceSchemaLocation="assignment1.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <CLIENT>
  <clientID>070555</clientID>
  <name>Smith, John</name>
  <address>2 Smith Street, Johnstown</address>
  <phone>0419333333</phone>
 </CLIENT>
 <CLIENT>
  <clientID>070556</clientID>
  <name>Smith, Jenny</name>
  <address>2 Smith Street, Johnstown</address>
  <phone>0419444444</phone>
 </CLIENT>
 <CLIENT>
  <clientID>070888</clientID>
  <name>Nguyen, Paulette</name>
  <address>41 Waterloo Crescent, Waterloo</address>
  <phone>0419555555</phone>
 </CLIENT>
 <FLIGHT>
  <flightID>QZ485</flightID>
  <depDate>2007-09-17</depDate>
  <depTime>09:05:00</depTime>
  <arrDate>2007-09-17</arrDate>
  <arrTime>12:30:00</arrTime>
  <origin>Adelaide</origin>
  <destination>Sydney</destination>
 </FLIGHT>
 <FLIGHT>
  <flightID>JQ762</flightID>
  <depDate>2007-09-22</depDate>
  <depTime>12:50:00</depTime>
  <arrDate>2007-09-22</arrDate>
  <arrTime>14:25:00</arrTime>
  <origin>Sydney</origin>
  <destination>Adelaide</destination>
 </FLIGHT>
 <FLIGHT>
  <flightID>XP111</flightID>
  <depDate>2007-09-20</depDate>
  <depTime>22:10:00</depTime>
  <arrDate>2007-09-21</arrDate>
  <arrTime>06:05:00</arrTime>
  <origin>Perth</origin>
  <destination>Sydney</destination>
 </FLIGHT>
 <BOOKING>
  <flightID>JQ762</flightID>
  <clientID>070555</clientID>
  <class>economy</class>
 </BOOKING>
 <BOOKING>
  <flightID>JQ762</flightID>
  <clientID>070556</clientID>
  <class>economy</class>
 </BOOKING>
 <BOOKING>
  <flightID>QZ485</flightID>
  <clientID>070555</clientID>
  <class>economy</class>
 </BOOKING>
 <BOOKING>
  <flightID>QZ485</flightID>
  <clientID>070556</clientID>
  <class>economy</class>
 </BOOKING>
 <BOOKING>
  <flightID>XP111</flightID>
  <clientID>070888</clientID>
  <class>business</class>
 </BOOKING>
 <BOOKING>
  <flightID>JQ762</flightID>
  <clientID>070888</clientID>
  <class>business</class>
 </BOOKING>
</FlightDetails>


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
54.688ms