zoukankan      html  css  js  c++  java
  • 复合类型

    复合类型

    本章内容

    • 复合空元素

    • 仅含元素的复合类型

    • xml schema复合元素仅含文本

    • 混合内容的复合类型


    XSD空元素

    特点:

    空的复合元素不能包含内容,只能含有属性。

    实例:

    xml空元素:

    <product prodid="1345" />
    • "product" 元素根本没有内容。为了定义无内容的类型,我们就必须声明一个在其内容中只能包含元素的类型

    • 并不会声明任何元素

    xsd元素:

    <xs:element name="product">
     <xs:complexType>
       <xs:complexContent>
         <xs:restriction base="xs:integer">
           <xs:attribute name="prodid" type="xs:positiveInteger"/>
         </xs:restriction>
       </xs:complexContent>
     </xs:complexType>
    </xs:element>
    • complexType是复合内容的复合类型

    • complexContent给出的信号是,我们打算限定或者拓展某个复合类型的内容模型

    • integer 限定则声明了一个属性但不会引入任何的元素内容

    也可以:

    <xs:element name="product">
     <xs:complexType>
       <xs:attribute name="prodid" type="xs:positiveInteger"/>
     </xs:complexType>
    </xs:element>

    还可以:可以为一个 complexType 元素起一个名字,然后为 "product" 元素设置一个 type 属性并引用这个 complexType 名称(通过使用此方法,若干个元素均可引用相同的复合类型)

    <xs:element name="product" type="prodtype"/>

    <xs:complexType name="prodtype">
     <xs:attribute name="prodid" type="xs:positiveInteger"/>
    </xs:complexType>

    仅含元素的复合类型

    特点:

    "仅含元素"的复合类型元素是只能包含其他元素的元素。

    实例:

    XML

    <person>
     <firstname>John</firstname>
     <lastname>Smith</lastname>
    </person>

    schema中定义的person

    <xs:element name="person">
     <xs:complexType>
       <xs:sequence>
         <xs:element name="firstname" type="xs:string"/>
         <xs:element name="lastname" type="xs:string"/>
       </xs:sequence>
     </xs:complexType>
    </xs:element>

    方法二:

    complexType 元素设定一个名称,并让 "person" 元素的 type 属性来引用此名称(如使用此方法,若干元素均可引用相同的复合类型)

    <xs:element name="person" type="persontype"/>

    <xs:complexType name="persontype">
     <xs:sequence>
       <xs:element name="firstname" type="xs:string"/>
       <xs:element name="lastname" type="xs:string"/>
     </xs:sequence>
    </xs:complexType>

    xml schema复合元素仅含文本

    特点:

    仅含文本的复合元素可包含文本和属性。

    仅含文本的复合元素实例:

    此类型仅包含简易的内容(文本和属性),因此我们要向此内容添加 simpleContent 元素当使用简易内容时,我们就必须在 simpleContent 元素内定义扩展或限定

    <xs:element name="somename">
     <xs:complexType>
       <xs:simpleContent>
         <xs:extension base="basetype">
          ....
          ....
         </xs:extension>
       </xs:simpleContent>
     </xs:complexType>
    </xs:element>

    或者:

    <xs:element name="somename">
     <xs:complexType>
       <xs:simpleContent>
         <xs:restriction base="basetype">
          ....
          ....
         </xs:restriction>
       </xs:simpleContent>
     </xs:complexType>
    </xs:element>

    XML

    <shoesize country="france">35</shoesize>

    下面这个例子声明了一个复合类型,其内容被定义为整数值,并且 "shoesize" 元素含有名为 "country" 的属性

    <xs:element name="shoesize">
     <xs:complexType>
       <xs:simpleContent>
         <xs:extension base="xs:integer">
           <xs:attribute name="country" type="xs:string" />
         </xs:extension>
       </xs:simpleContent>
     </xs:complexType>
    </xs:element>

    也可为 complexType 元素设定一个名称,并让 "shoesize" 元素的 type 属性来引用此名称(通过使用此方法,若干元素均可引用相同的复合类型)

    <xs:element name="shoesize" type="shoetype"/>

    <xs:complexType name="shoetype">
     <xs:simpleContent>
       <xs:extension base="xs:integer">
         <xs:attribute name="country" type="xs:string" />
       </xs:extension>
     </xs:simpleContent>
    </xs:complexType>

    XSD混合内容

    特点:

    混合的复合类型可包含属性、元素以及文本

    XML

    <letter>
      Dear Mr.<name>John Smith</name>.
      Your order <orderid>1032</orderid>
      will be shipped on <shipdate>2001-07-13</shipdate>.
    </letter>

    同样的元素再schema中

    <xs:element name="letter">
      <xs:complexType mixed="true">
        <xs:sequence>
          <xs:element name="name" type="xs:string"/>
          <xs:element name="orderid" type="xs:positiveInteger"/>
          <xs:element name="shipdate" type="xs:date"/>
        </xs:sequence>
      </xs:complexType>
    </xs:element>
    <!--
    为了使字符数据可以出现在 "letter" 的子元素之间,**mixed** 属性必须被设置为 "true"。<xs:sequence> 标签 (name、orderid 以及 shipdate ) 意味着被定义的元素必须依次出现在 "letter" 元素内部
    -->

    也可以为 complexType 元素起一个名字,并让 "letter" 元素的 type 属性引用 complexType 的这个名称(通过这个方法,若干元素均可引用同一个复合类型)

    <xs:element name="letter" type="lettertype"/>
    
    <xs:complexType name="lettertype" mixed="true">
        <!--后面大同小于,前面设置有讲究-->
      <xs:sequence>
        <xs:element name="name" type="xs:string"/>
        <xs:element name="orderid" type="xs:positiveInteger"/>
        <xs:element name="shipdate" type="xs:date"/>
      </xs:sequence>
    </xs:complexType>
    It's a lonely road!!!
  • 相关阅读:
    随机变量和期望
    lj的锁
    lyd的旅行
    sg函数和nim游戏的关系
    game with probability problem
    cf 853 B Jury Meeting [前缀和]
    cf 853 A planning [贪心]
    [ZJOI2015][bzoj3924] 幻想乡战略游戏 [动态点分治]
    [IOI2011] Race [点分治]
    [网络流24题] 星际转移问题
  • 原文地址:https://www.cnblogs.com/JunkingBoy/p/14641887.html
Copyright © 2011-2022 走看看