以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 DTD/XML Schema 』  (http://bbs.xml.org.cn/list.asp?boardid=23)
----  作业,求人写一个XML的SCHEMA(急)  (http://bbs.xml.org.cn/dispbbs.asp?boardid=23&rootid=&id=59509)


--  作者:yorsal
--  发布时间:3/6/2008 3:05:00 PM

--  作业,求人写一个XML的SCHEMA(急)
<?xml version="1.0"?>
<customers xsi:noNamespaceSchemaLocation="schema01.xsd"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

 <customer cno="C111" corporate="false">
  <cname>
   <gName>Bilbo</gName>
   <fName>Baggins</fName>
  </cname>
  <caddress>
   <cstreet>21 Bag End</cstreet>
   <csuburb>Hobbiton</csuburb>
   <cstate>VIC</cstate>
   <cpostcode>3077</cpostcode>
  </caddress>
  <contacts>
   <home primary="true">(03) 9903-3401</home>
   <office>(03) 9903-3401</office>
   <mobile>04111222333</mobile>
  </contacts>
 </customer>
 <customer cno="C222" corporate="true">
  <cname>
   <companyName>PBL Ltd</companyName>
  </cname>
  <caddress>
   <cstreet>10 Rich Road</cstreet>
   <csuburb>Moneytown</csuburb>
   <cstate>VIC</cstate>
   <cpostcode>3454</cpostcode>
  </caddress>
  <contacts>
   <name>James Packer</name>
   <office primary="true">(03) 9111-9999</office>
   <mobile>04111222444</mobile>
  </contacts>
  <flights>
   <flight no="F112">
    <flightDate>2007-06-21</flightDate>
    <flightDetail>
     <legNo>L001</legNo>
     <dest>Melbourne</dest>
     <seats>7</seats>
     <seatPrice>250</seatPrice>
     <discount>2</discount>
    </flightDetail>
    <flightDetail>
     <legNo>L002</legNo>
     <dest>Sydney</dest>
     <seats>20</seats>
     <seatPrice>225</seatPrice>
     <discount>5</discount>
    </flightDetail>
   </flight>
   <flight no="F121">
    <flightDate>2006-01-20</flightDate>
    <flightDetail>
     <legNo>L001</legNo>
     <dest>Albury</dest>
     <seats>25</seats>
     <seatPrice>57.50</seatPrice>
     <discount>0</discount>
    </flightDetail>
    <flightDetail>
     <legNo>L002</legNo>
     <dest>Sydney</dest>
     <seats>34</seats>
     <seatPrice>215</seatPrice>
     <discount>5</discount>
    </flightDetail>
   </flight>
   <flight no="F111">
    <flightDate>2007-04-12</flightDate>
    <flightDetail>
     <legNo>L001</legNo>
     <dest>Hobart</dest>
     <seats>4</seats>
     <seatPrice>125</seatPrice>
     <discount>0</discount>
    </flightDetail>
    <flightDetail>
     <legNo>L002</legNo>
     <dest>Melbourne</dest>
     <seats>100</seats>
     <seatPrice>190</seatPrice>
     <discount>10</discount>
    </flightDetail>
   </flight>
  </flights>
 </customer>
 <customer cno="C333" corporate="false">
  <cname>
   <gName>Clark</gName>
   <fName>Kent</fName>
  </cname>
  <caddress>
   <cstreet>10 Super St</cstreet>
   <csuburb>Smallville</csuburb>
   <cstate>VIC</cstate>
   <cpostcode>3622</cpostcode>
  </caddress>
  <contacts>
   <home>(03) 9111-3333</home>
   <office>(03) 9111-9999</office>
   <mobile primary="true">04111222444</mobile>
  </contacts>
  <flights>
   <flight no="F113">
    <flightDate>2006-01-21</flightDate>
    <flightDetail>
     <legNo>L001</legNo>
     <dest>Adelaide</dest>
     <seats>2</seats>
     <seatPrice>300</seatPrice>
     <discount>20</discount>
    </flightDetail>
   </flight>
   <flight no="F114">
    <flightDate>2007-07-10</flightDate>
    <flightDetail>
     <legNo>L002</legNo>
     <dest>Perth</dest>
     <seats>2</seats>
     <seatPrice>400</seatPrice>
     <discount>20</discount>
    </flightDetail>
    <flightDetail>
     <legNo>L003</legNo>
     <dest>Rottnest Island</dest>
     <seats>2</seats>
     <seatPrice>55.5</seatPrice>
     <discount>5</discount>
    </flightDetail>
   </flight>
   <flight no="F122">
    <flightDate>2007-01-01</flightDate>
    <flightDetail>
     <legNo>L001</legNo>
     <dest>Darwin</dest>
     <seats>32</seats>
     <seatPrice>230</seatPrice>
     <discount>20</discount>
    </flightDetail>
   </flight> 
   <flight no="F115">
    <flightDate>2007-07-11</flightDate>
    <flightDetail>
     <legNo>L001</legNo>
     <dest>Bendigo</dest>
     <seats>20</seats>
     <seatPrice>100</seatPrice>
     <discount>10</discount>
    </flightDetail>
    <flightDetail>
     <legNo>L002</legNo>
     <dest>Ballarat</dest>
     <seats>20</seats>
     <seatPrice>50</seatPrice>
     <discount>10</discount>
    </flightDetail>
    <flightDetail>
     <legNo>L003</legNo>
     <dest>Albury</dest>
     <seats>20</seats>
     <seatPrice>75</seatPrice>
     <discount>10</discount>
    </flightDetail>
    <flightDetail>
     <legNo>L004</legNo>
     <dest>Wangaratta</dest>
     <seats>20</seats>
     <seatPrice>66</seatPrice>
     <discount>10</discount>
    </flightDetail>
    <flightDetail>
     <legNo>L005</legNo>
     <dest>Wyong</dest>
     <seats>20</seats>
     <seatPrice>45</seatPrice>
     <discount>0</discount>
    </flightDetail>
    <flightDetail>
     <legNo>L006</legNo>
     <dest>Newcastle</dest>
     <seats>20</seats>
     <seatPrice>110</seatPrice>
     <discount>10</discount>
    </flightDetail>
    <flightDetail>
     <legNo>L007</legNo>
     <dest>Tweed Heads</dest>
     <seats>20</seats>
     <seatPrice>89</seatPrice>
     <discount>10</discount>
    </flightDetail>
   </flight>
  </flights>
 </customer>
 <customer cno="C444" corporate="false">
  <cname>
   <gName>Peter</gName>
   <fName>Pan</fName>
  </cname>
  <caddress>
   <cstreet>23 Never Street</cstreet>
   <csuburb>Never Never Land</csuburb>
   <cstate>WA</cstate>
   <cpostcode>6200</cpostcode>
  </caddress>
  <contacts>
   <home>(06) 6222-3333</home>
   <office>(06) 6222-9999</office>
   <mobile primary="true">04111222555</mobile>
  </contacts>
  <flights>
   <flight no="F116">
    <flightDate>2007-12-12</flightDate>
    <flightDetail>
     <legNo>L001</legNo>
     <dest>Melbourne</dest>
     <seats>1</seats>
     <seatPrice>200</seatPrice>
     <discount>0</discount>
    </flightDetail>
    <flightDetail>
     <legNo>L002</legNo>
     <dest>Sydney</dest>
     <seats>4</seats>
     <seatPrice>190</seatPrice>
     <discount>3</discount>
    </flightDetail>
    <flightDetail>
     <legNo>L003</legNo>
     <dest>Brisbane</dest>
     <seats>9</seats>
     <seatPrice>150</seatPrice>
     <discount>0</discount>
    </flightDetail>
   </flight>
   <flight no="F117">
    <flightDate>2007-06-16</flightDate>
    <flightDetail>
     <legNo>L001</legNo>
     <dest>Darwin</dest>
     <seats>10</seats>
     <seatPrice>400</seatPrice>
     <discount>0</discount>
    </flightDetail>
   </flight>
   <flight no="F123">
    <flightDate>2007-06-17</flightDate>
    <flightDetail>
     <legNo>L001</legNo>
     <dest>Albury</dest>
     <seats>30</seats>
     <seatPrice>187</seatPrice>
     <discount>0</discount>
    </flightDetail>
   </flight>
  </flights>
 </customer>
 <customer cno="C555" corporate="false">
  <cname>
   <gName>Bruce</gName>
   <fName>Wayne</fName>
  </cname>
  <caddress>
   <cstreet>23 Batman Ave</cstreet>
   <csuburb>Gotham City</csuburb>
   <cstate>WA</cstate>
   <cpostcode>6500</cpostcode>
  </caddress>
  <contacts>
   <home>(06) 6222-4444</home>
   <office>(06) 6222-9999</office>
   <mobile primary="true">04111222666</mobile>
  </contacts>
  <flights>
   <flight no="F120">
    <flightDate>2007-05-05</flightDate>
    <flightDetail>
     <legNo>L001</legNo>
     <dest>Sydney</dest>
     <seats>15</seats>
     <seatPrice>200</seatPrice>
     <discount>4</discount>
    </flightDetail>
   </flight>
  </flights>
 </customer>
 <customer cno="C666" corporate="true">
  <cname>
   <companyName>Newscorp</companyName>
  </cname>
  <caddress>
   <cstreet>1 News Drive</cstreet>
   <csuburb>Subiaco</csuburb>
   <cstate>WA</cstate>
   <cpostcode>6666</cpostcode>
  </caddress>
  <contacts>
   <name>Rupert Murdoch</name>
   <office primary="true">(06) 6222-9999</office>
   <mobile>04111222555</mobile>
  </contacts>
  <flights>
   <flight no="F118">
    <flightDate>2007-04-12</flightDate>
    <flightDetail>
     <legNo>L001</legNo>
     <dest>Burnie</dest>
     <seats>2</seats>
     <seatPrice>125</seatPrice>
     <discount>5</discount>
    </flightDetail>
    <flightDetail>
     <legNo>L001</legNo>
     <dest>Strachan</dest>
     <seats>2</seats>
     <seatPrice>60</seatPrice>
     <discount>5</discount>
    </flightDetail>
    <flightDetail>
     <legNo>L001</legNo>
     <dest>Queenstown</dest>
     <seats>2</seats>
     <seatPrice>45</seatPrice>
     <discount>5</discount>
    </flightDetail>
    <flightDetail>
     <legNo>L001</legNo>
     <dest>Hobart</dest>
     <seats>2</seats>
     <seatPrice>125</seatPrice>
     <discount>5</discount>
    </flightDetail>
    <flightDetail>
     <legNo>L001</legNo>
     <dest>Launceston</dest>
     <seats>2</seats>
     <seatPrice>78</seatPrice>
     <discount>5</discount>
    </flightDetail>
    <flightDetail>
     <legNo>L001</legNo>
     <dest>Melbourne</dest>
     <seats>2</seats>
     <seatPrice>125</seatPrice>
     <discount>5</discount>
    </flightDetail>
    <flightDetail>
     <legNo>L001</legNo>
     <dest>Geelong</dest>
     <seats>2</seats>
     <seatPrice>50</seatPrice>
     <discount>5</discount>
    </flightDetail>
   </flight>
   <flight no="F119">
    <flightDate>2007-07-01</flightDate>
    <flightDetail>
     <legNo>L001</legNo>
     <dest>Sydney</dest>
     <seats>25</seats>
     <seatPrice>225</seatPrice>
     <discount>5</discount>
    </flightDetail>
    <flightDetail>
     <legNo>L001</legNo>
     <dest>Newcastle</dest>
     <seats>25</seats>
     <seatPrice>125</seatPrice>
     <discount>0</discount>
    </flightDetail>
   </flight>
  </flights>
 </customer>
</customers>



--  作者:yorsal
--  发布时间:3/6/2008 3:06:00 PM

--  
这个是我自己写的,在XMLWRITER下面出错,不知道怎么调试,高手帮忙啊

<?xml version="1.0"?>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <xsd:annotation>
    <xsd:documentation>
      This XML Schema is for the customer flights XML file
      This Schema file is called "schema01.xsd"
    </xsd:documentation>
  </xsd:annotation>
  
  <!-- ********************1st layer************************* -->
  <!-- ROOT -->
  <xsd:element name="customers" >  
 <xsd:complexType>
   <xsd:sequence>
    <xsd:element ref="customer" maxOccurs="unbounded"/>
   </xsd:sequence>
 </xsd:complexType>
  </xsd:element>
  
  
  <!-- ********************2nd layer************************* -->
  <!-- CUSTOMER ELEMENT -->  
  <xsd:element name="customer" >  
 <xsd:complexType>
   <xsd:sequence>
    <xsd:element ref="cname"/>
    <xsd:element ref="caddress"/>
    <xsd:element ref="contacts"/>
    <xsd:element ref="flights" minOccurs="0"/>
   </xsd:sequence>
   <!-- ATTRIBUTE -->
   <xsd:attribute name="cno" type="xsd:string" use="required"/>
   <xsd:attribute name="corporate" type="xsd:boolean" use="required"/>
   
 </xsd:complexType>
  </xsd:element>
  
  <!-- CNAME ELEMENT -->
  <xsd:element name="cname" >  
 <xsd:complexType>
   <xsd:sequence>
    <xsd:element ref="gName" minOccurs="0"/>
    <xsd:element ref="fName" minOccurs="0"/>
    <xsd:element ref="companyName" minOccurs="0"/>
   </xsd:sequence>
 </xsd:complexType>
  </xsd:element>
  
  <!-- CADDRESS ELEMENT -->  
  <xsd:element name="caddress" >  
 <xsd:complexType>
   <xsd:sequence>
    <xsd:element ref="cstreet"/>
    <xsd:element ref="csuburb"/>
    <xsd:element ref="cstate"/>
    <xsd:element ref="cpostcode"/>
   </xsd:sequence>
 </xsd:complexType>
  </xsd:element>
  
  <!-- CONTACTS ELEMENT -->
  <xsd:element name="contacts" >  
 <xsd:complexType>
   <xsd:sequence>
    <xsd:choice>
    <xsd:element ref="home"/>
    <xsd:element ref="name"/>
  </xsd:choice>
  <xsd:element ref = "mobile"/>
  <xsd:element ref = "office"/>
   </xsd:sequence>
 </xsd:complexType>
  </xsd:element>
  
  <!-- FLIGHTS ELEMENT -->  
  <xsd:element name="flights" >  
 <xsd:complexType>
   <xsd:sequence>
    <xsd:element ref="flight" maxOccurs="4"/>
   </xsd:sequence>
 </xsd:complexType>
  </xsd:element>
  
  
  <!-- ********************3rd layer************************* -->
  <!-- GNAME&FNAME ELEMENT -->
  <xsd:element name="gName" type="xsd:string"/>
  <xsd:element name="fName" type="xsd:string"/>
  <xsd:element name="companyName" type="xsd:string"/>
  
  <!-- STREET&SUBURB&STATE&POSTCODE ELEMENT -->
  <xsd:element name="cstreet" type="xsd:string"/>
  <xsd:element name="csuburb" type="xsd:string"/>
  <xsd:element name="cstate" type="xsd:string"/>
  <xsd:element name="cpostcode" type="xsd:integer"/>
  
  <!-- MOBILE&HOME&OFFICE&NAME ELEMENT -->
  <xsd:element name="name" type="xsd:string"/>
  
  <xsd:element name="home">  
 <xsd:complexType>
   <xsd:attribute name="primary" type="xsd:boolean" use="optional"/>
 </xsd:complexType>
  </xsd:element>
  <xsd:element name="mobile">  
 <xsd:complexType>
   <xsd:attribute name="primary" type="xsd:boolean" use="optional"/>
 </xsd:complexType>
  </xsd:element>
  
  <xsd:element name="office">  
 <xsd:complexType>
   <xsd:attribute name="primary" type="xsd:boolean" use="optional"/>
 </xsd:complexType>
  </xsd:element>
  
  <!-- FLIGHT ELEMENT -->  
  <xsd:element name="flight" >  
 <xsd:complexType>
   <xsd:sequence>
    <xsd:element ref="flightDate"/>
    <xsd:element ref="flightDetail" maxOccurs="7"/>
   </xsd:sequence>
   <!-- ATTRIBUTE -->
   <xsd:attribute name = "no" type="xsd:string" />
 </xsd:complexType>
  </xsd:element>


  <!-- ********************4th layer************************* -->
  <!-- FLIGHTDATE ELEMENT -->
  <xsd:element name="flightDate" type="xsd:integer"/>
  
  <!-- FLIGHTDETAIL ELEMENT -->
  <xsd:element name="flightDetail" >  
 <xsd:complexType>
   <xsd:sequence>
    <xsd:element ref="legNo"/>
    <xsd:element ref="dest"/>
    <xsd:element ref="seats"/>
    <xsd:element ref="seatPrice"/>
    <xsd:element ref="discount"/>
   </xsd:sequence>
 </xsd:complexType>
  </xsd:element>
  
  <!-- LEGNO&DEST.. ELEMENT -->
  <xsd:element name="legNo" type="xsd:integer"/>
  <xsd:element name="dest" type="xsd:string"/>
  <xsd:element name="seats" type="xsd:integer"/>
  <xsd:element name="seatPrice" type="xsd:integer"/>
  <xsd:element name="discount" type="xsd:integer"/>

</xsd:schema>


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