嘟嘟

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  26 Posts :: 0 Stories :: 6 Comments :: 0 Trackbacks

定义参数
<xsd:element name="order">
 <xsd:complexType>
  <xsd:attribute name="shirts" type="xsd:integer"/>
  <xsd:attribute name="mugs" type="xsd:integer"/>
  <xsd:attribute name="hats" type="xsd:integer"/>
 </xsd:complexType>
</xsd:element>
XML文件:
<oeder shirts="9" mugs="3" hats="45">

参数使用定义
<xsd:attribute name="hats" type="xsd:integer" use="required"/>                //必须出现
<xsd:attribute name="hats" type="xsd:integer" use="optional"/>                //可选
<xsd:attribute name="hats" type="xsd:integer" use="prohibited"/>              //禁止
<xsd:attribute name="hats" type="xsd:integer" use="fixed" value="value"/>     //如果有这个参数,必须是这个值
<xsd:attribute name="hats" type="xsd:integer" use="default" value="value"/>   //如果没有这个参数,自动加上这个参数

参数和元素
 <xsd:element name="order">
 <xsd:complexType>
  <xsd:sequence>
   <xsd:element name="shirts" type="xsd:string"/>
   <xsd:element name="sweatshirts" type="xsd:string"/>
   <xsd:element name="mugs" type="xsd:string"/>
   <xsd:element name="hats" type="xsd:string"/>
  </xsd:sequence>
  <xsd:attribute name="orderDate" type="xsd:date"/>
  <xsd:attribute name="source" type="xsd:string"/>
 </xsd:complexType>
 </xsd:element>
 XML文件:
 <order orderDate="2001-04-18" source="cellphone">
 <shirt>aaa</shirt>
 <sweatshirts>bbb</sweatshirts>
 <mugs>ccc</mugs>
 <hats>ddd</hats>
 </order>

参数和text
<shirt quantity="4">XL purple</shirt>

  <xsd:element name="shirt">
 <xsd:complexType>
  <xsd:simpleContent>
   <xsd:restriction base="xsd:string">                        <!-->文本有限制<-->
    <xsd:maxLength value="30" />
    <xsd:attribute name="quantity" type="xsd:integer"/>
   </xsd:restriction>
  </xsd:simpleContent> >
 </xsd:complexType>
  </xsd:element>

  <xsd:element name="shirt">
 <xsd:complexType>
  <xsd:simpleContent>
   <xsd:extension base="xsd:string">      <!-->文本无限制<-->   
    <xsd:attribute name="quantity" type="xsd:integer"/>
   </xsd:extension>
  </xsd:simpleContent>
 </xsd:complexType>
  </xsd:element>

参数 text 嵌入元素
 <order orderDate="2001-04-18">
        to ship overnight
 <shirt>9</shirt>
        and
 <mugs>7</mugs>
 to fairfax
 </order>
 <xsd:element name="order">
 <xsd:complexType mixed="true">
  <xsd:sequence>
   <xsd:element name="shirts" type="xsd:string"/>
   <xsd:element name="mugs" type="xsd:string"/>
  </xsd:sequence>
  <xsd:attribute name="orderDate" type="xsd:date"/>
 </xsd:complexType>
 </xsd:element>

用户自定义
<!-- define simple types -->
  <xsd:simpleType name="colorType">
 <xsd:restriction base="xsd:string">
  <xsd:enumeration value="purple" />
  <xsd:enumeration value="orange" />
  <xsd:enumeration value="blue" />
  <xsd:enumeration value="grey" />
 </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="sizeType">
 <xsd:restriction base="xsd:string">
  <xsd:enumeration value="M" />
  <xsd:enumeration value="L" />
  <xsd:enumeration value="XL" />
 </xsd:restriction>
  </xsd:simpleType>

  <!-- define complex type -->
  <xsd:complexType name="sizeColorType">
 <xsd:sequence>
  <xsd:element name="size" type="sizeType" />
  <xsd:element name="color" type="colorType" />
 </xsd:sequence>
 <xsd:attribute name="quantity" type="xsd:integer" />
  </xsd:complexType>

  使用定义得类型
  <!-- define elements -->
  <xsd:element name="shirt" type="sizeColorType" />

  XML文件:
  <shirt quantity="2">
 <size>M</size>
 <color>blue</color>
  </shirt>

关联元素和参数 (重用)
<xsd:element name="shirt" type="xsd:string" />
<xsd:element name="shirt_list">
 <xsd:complexType>
  <xsd:sequence>
   <xsd:element ref="shirt" maxOc-curs="unbounded" />
  </xsd:sequence>
 </xsd:complexType>
</xsd:element>

<xsd:attribute name="quantity" type="xsd:nonNegativeInteger"/>
<xsd:complexType name="quantityAttrType">
 <xsd:attribute ref="quantity"/>
</xsd:complexType>
<xsd:element name="mugs" type="quantityAttrType"/>
<xsd:element name="hats" type="quantityAttrType"/>

建立复杂类型基于已存类型
 <!-- define simple types -->
 <xsd:simpleType name="colorType">
 <xsd:restriction base="xsd:string">
 <xsd:enumeration value="purple"/>
 <xsd:enumeration value="orange"/>
 <xsd:enumeration value="blue"/>
 <xsd:enumeration value="grey"/>
 </xsd:restriction>
 </xsd:simpleType>
 <xsd:simpleType name="sizeType">
 <xsd:restriction base="xsd:string">
 <xsd:enumeration value="M"/>
 <xsd:enumeration value="L"/>
 <xsd:enumeration value="XL"/>
 </xsd:restriction>
 </xsd:simpleType>
 
 
 <!-- define complex types -->
 <xsd:complexType name="sizeColorType">
 <xsd:sequence>
 <xsd:element name="size" type="sizeType"/>
 <xsd:element name="color" type="colorType"/>
 </xsd:sequence>
 <xsd:attribute ref="quantity"/>
 </xsd:complexType>
 
 <xsd:complexType name="shirtDescType">
 <xsd:complexContent>
 <xsd:extension base="sizeColorType">
  <xsd:sequence>
  <xsd:element name="material" type="xsd:string" />
  <xsd:element name="collar" type="xsd:string" />
  <xsd:element name="sleeve" type="xsd:string" />
  </xsd:sequence>
 </xsd:extension>
 </xsd:complexContent>
 </xsd:complexType> 
 
 <!--define attribute -->
 <xsd:attribute name="quantity" type="xsd:nonNegativeInteger"/>
 
 <!-- define element -->
 <xsd:element name="shirt" type="shirtDescType"/>

元素分组
 <!-- define simple types -->
 <xsd:simpleType name="colorType">
 <xsd:restriction base="xsd:string">
  <xsd:enumeration value="purple"/>
  <xsd:enumeration value="orange"/>
  <xsd:enumeration value="blue"/>
  <xsd:enumeration value="grey"/>
 </xsd:restriction>
 </xsd:simpleType>
 <xsd:simpleType name="sizeType">
 <xsd:restriction base="xsd:string">
  <xsd:enumeration value="M"/>
  <xsd:enumeration value="L"/>
  <xsd:enumeration value="XL"/>
 </xsd:restriction>
 </xsd:simpleType>
  
 <!-- define group -->
 <xsd:group name="sizeColorGroup">
 <xsd:sequence>
  <xsd:element name="size" type="sizeType"/>
  <xsd:element name="color" type="colorType"/>
 </xsd:sequence>
 </xsd:group>

 <!-- define elements -->
 <xsd:element name="shirt">
 <xsd:complexType>
  <xsd:group ref="sizeColorGroup" />
 </xsd:complexType>
 </xsd:element>
 
参数分组
 <!-- define simple types -->
 <xsd:simpleType name="colorType">
 <xsd:restriction base="xsd:string">
  <xsd:enumeration value="purple"/>
  <xsd:enumeration value="orange"/>
  <xsd:enumeration value="blue"/>
  <xsd:enumeration value="grey"/>
 </xsd:restriction>
 </xsd:simpleType>
 <xsd:simpleType name="sizeType">
 <xsd:restriction base="xsd:string">
  <xsd:enumeration value="M"/>
  <xsd:enumeration value="L"/>
  <xsd:enumeration value="XL"/>
 </xsd:restriction>
 </xsd:simpleType>
  
 <!-- define attribute group -->
 <xsd:attributeGroup name="clothesAttrGroup">
 <xsd:attribute name="quantity" type="xsd:nonNegativeInteger" />
 <xsd:attribute name="color" type="colorType" />
 <xsd:attribute name="size" type="sizeType" />
 <xsd:attribute name="material" type="xsd:string" />
 </xsd:attributeGroup>

 <!-- define elements -->
 <xsd:element name="shirt">
 <xsd:complexType>
  <xsd:attributeGroup ref="clothesAttrGroup" />
 </xsd:complexType>
 </xsd:element>
 
Annotation 和 Documentation
 在schema文件中加入注释
 <xsd:annotation>
 <xsd:documentation>
  text.....
 </xsd:documentation>
 </xsd:annotation>

include外部xsd文件
 1: <xsd:include schemaLocation="filename.xsd" />   //不能重定义
 2: <xsd:redefine schemaLocation="shirts.xsd">      //重定义
       ....
    </xsd:redefine>

posted on 2007-06-15 03:53 fyp1210 阅读(359) 评论(0)  编辑  收藏 所属分类: XML

只有注册用户登录后才能发表评论。


网站导航: