XML Schema restriction 元素

ການກໍານົດ ແລະ ການນໍາໃຊ້

restriction 元素定义对 simpleType、simpleContent ຫຼື complexContent 定义的约束。

ຂໍ້ມູນປະເພດ

ການອອກໄດ້ ເທື່ອດຽວ
ປະເພດຜູ້ປົກຄອງ ພາຍໃນປະເພດ
complexContent ຂັ້ນນໍາ

group、all、choice、sequence、attribute、attributeGroup、anyAttribute

ພາສາ
<restriction
id=ID
any attributes
base=QName
>
(annotation?,(simpleType?,(minExclusive|minInclusive| 
maxExclusive|maxInclusive|totalDigits|fractionDigits|
length|minLength|maxLength|enumeration|whiteSpace|pattern)*))
Content for simpleContent:
(annotation?,(simpleType?,(minExclusive |minInclusive| 
maxExclusive|maxInclusive|totalDigits|fractionDigits|
(length|minLength|maxLength|enumeration|whiteSpace|pattern)*)?, 
((attribute|attributeGroup)*,anyAttribute?))
Content for complexContent:
(annotation?,(group|all|choice|sequence)?,
((attribute|attributeGroup)*,anyAttribute?))
</restriction>

(? ສັນຍາການພາຍໃນ ປະເພດ restriction ບັນດາປະເພດທີ່ສາມາດອອກໄດ້ບໍ່ມີຫຼືຫຼຽນເທື່ອດຽວ).

ບັນດາປະເພດ ການອະທິບາຍ
id ທາງເລືອກຢູ່. ກໍານົດ ID ສະບາຍສະເພາະຂອງປະເພດນັ້ນ.
base ຈຳເປັນ. ກໍານົດຊື່ຂອງປະເພດພາຍໃນ data type, simpleType ຫຼື complexType ທີ່ຖືກກໍານົດໃນ schema (ຫຼື schema ອື່ນໆທີ່ອອກແບບຈາກ namespace ທີ່ກໍານົດໄວ້).
any attributes ທາງເລືອກຢູ່. ກໍານົດບັນດາບັນດາປະເພດອື່ນໆທີ່ມີນອກບໍ່ໄດ້ພາຍໃນຂອງ schema.

ບົດສະຫຼຸບ

ບົດສະຫຼຸບ 1

ບົດສະຫຼຸບນີ້ພົບວ່າມີປະເພດ "age" ຊຶ່ງມີຂໍ້ຈຳກັດ ຊຶ່ງມີຊື່ "age" ຕ້ອງບໍ່ຕໍ່າກວ່າ 0 ຫຼືຫຼາຍກວ່າ 100:

<xs:element name="age">
  <xs:simpleType>
    <xs:restriction base="xs:integer">
      <xs:minInclusive value="0"/>
      <xs:maxInclusive value="100"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

ບົດສະຫຼຸບ 2

ບົດສະຫຼຸບນີ້ພົບວ່າມີປະເພດ "initials" ຊຶ່ງມີຂໍ້ຈຳກັດ. "initials" ປະເພດ "initials" ມີຂໍ້ຈຳກັດ ທີ່ມີຄວາມສະນັບສະນູນຈາກ a ຫາ z ສາມຄວາມຫຼາຍກວ່າຂອງພາສາລາວ:

<xs:element name="initials">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:pattern value="[a-zA-Z][a-zA-Z][a-zA-Z]"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

ບົດສະຫຼຸບ 3

ບົດສະຫຼຸບນີ້ພົບວ່າມີປະເພດ "password" ຊຶ່ງມີຂໍ້ຈຳກັດ. "password" ປະເພດ "password" ມີຂໍ້ຈຳກັດ ຕ້ອງມີຄວາມສະນັບສະນູນຈາກ 5 ຄວາມແລະຫຼາຍກວ່າ 8 ຄວາມ:

<xs:element name="password">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:minLength value="5"/>
      <xs:maxLength value="8"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

ບົດສະຫຼຸບ 4

ບົດສະຫຼຸບນີ້ສະແດງການພັດທະນາປະເພດຍິງທີ່ມີຂໍ້ຈຳກັດ. ປະເພດ "Chinese_customer" ແມ່ນຖືກຍິງຈາກປະເພດ "customer" ທີ່ບໍ່ມີຂໍ້ຈຳກັດ, ຂໍ້ຂັດແຍ່ງ "country" ຂອງມັນມີຄວາມຄິດສະຫຼາກ "China":

<xs:complexType name="customer">
  <xs:sequence>
    <xs:element name="firstname" type="xs:string"/>
    <xs:element name="lastname" type="xs:string"/>
    <xs:element name="country" type="xs:string"/>
  </xs:sequence>
</xs:complexType>
<xs:complexType name="Chinese_customer">
  <xs:complexContent>
    <xs:restriction base="customer">
      <xs:sequence>
        <xs:element name="firstname" type="xs:string"/>
        <xs:element name="lastname" type="xs:string"/>
        <xs:element name="country" type="xs:string" fixed="China"/>
      </xs:sequence>
    </xs:restriction>
  </xs:complexContent>
</xs:complexType>