XSD complex type indicator

ຜ່ານສັນຍານພວກເຮົາສາມາດຄວບຄຸມວິທີທີ່ພວກເຮົານຳໃຊ້ປະກອບສິ່ງໃນເອກະສານ.

ສັນຍານ

ມີເຈັດແນວຄວາມຄຸມກຳນົດ:

ສັນຍານກຳນົດຢູ່ອັນຍາວ:

  • ທັງໝົດ
  • ຄວາມເລືອກ
  • ຕາມອັນຍາວ

ສັນຍານຄວາມຄຸມກຳນົດ:

  • maxOccurs
  • minOccurs

Group ສະຖານະການ:

  • Group name
  • attributeGroup name

Order ສະຖານະການ

Order ສະຖານະການຈະກຳນົດຄວາມຫຼາຍຄັກທີ່ສາມາດປະກົດຂຶ້ນຂອງຫຼັກໄດ້:

All ສະຖານະການ

<all> ສະຖານະການຈະກຳນົດຄວາມຫຼາຍຄັກທີ່ສາມາດປະກົດຂຶ້ນຂອງຫຼັກໄດ້ຕາມລຳດັບທີ່ບໍ່ມີຄວາມຫຼາຍກວ່າຫຼັກໄດ້ຕາມລຳດັບ, ແລະບໍ່ມີຫຼັກໄດ້ປະກົດຂຶ້ນຫຼາຍຄັກຫຼາຍຄັກ:

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

ຄວາມຄິດເຫັນ:ບໍ່ມີການນຳໃຊ້ <all> ສະຖານະການ, ທ່ານສາມາດກຳນົດ <minOccurs> ສຳລັບ 0 ຫຼື 1, ແລະສາມາດກຳນົດ <maxOccurs> ສະຖານະການ ສຳລັບ 1 (ຈະຖືກອະທິບາຍ <minOccurs> ແລະ <maxOccurs> ຫຼັງຈາກ).

Choice ສະຖານະການ

<choice> ສະຖານະການຈະກຳນົດຄວາມຫຼາຍຄັກທີ່ສາມາດປະກົດຂຶ້ນຂອງຫຼັກໄດ້ຕາມລຳດັບ (ຫຼາຍກວ່າຫຼັກໄດ້ຕາມລຳດັບ ຫຼື ຫຼາຍກວ່າຫຼັກໄດ້ຕາມລຳດັບ):

<xs:element name="person">
  <xs:complexType>
    <xs:choice>
      <xs:element name="employee" type="employee"/>
      <xs:element name="member" type="member"/>
    </xs:choice>
  </xs:complexType>
</xs:element>

ຄຳແນະນຳ:ສຳລັບທີ່ຈະກຳນົດຄວາມຫຼາຍຄັກທີ່ສາມາດປະກົດຂຶ້ນຂອງຫຼັກໄດ້ບໍ່ມີຄວາມຫຼາຍກວ່າຫຼາຍຄັກ, ສາມາດກຳນົດ <maxOccurs> (ຈະຖືກອະທິບາຍຫຼັງຈາກ) ສຳລັບ unbounded (ບໍ່ມີຄວາມຫຼາຍກວ່າ).

Sequence ສະຖານະການ

<sequence> ຈະກຳນົດຄວາມຫຼາຍຄັກທີ່ສາມາດປະກົດຂຶ້ນຂອງຫຼັກໄດ້ຕາມລຳດັບພິເສດ:

<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>

Occurrence ສະຖານະການ

Occurrence ສະຖານະການຈະກຳນົດຄວາມຫຼາຍຄັກທີ່ສາມາດປະກົດຂຶ້ນຂອງຫຼັກໄດ້:

ຄວາມຄິດເຫັນ:ສຳລັບທຸກ "Order" ແລະ "Group" ສະຖານະການ (any, all, choice, sequence, group name ແລະ group reference), maxOccurs ແລະminOccurs ຄົງທີ່ມີຄວາມຫຼາຍກວ່າ 1.

maxOccurs ສະຖານະການ

<maxOccurs> ສະຖານະການຈະກຳນົດຄວາມຫຼາຍຄັກທີ່ສາມາດປະກົດຂຶ້ນຂອງຫຼັກໄດ້:

<xs:element name="person">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="full_name" type="xs:string"/>
      <xs:element name="child_name" type="xs:string" maxOccurs="10"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

ບັນທັດທີ່ວ່າຫຼັກເພີ່ມ "child_name" ສາມາດປະກົດຂຶ້ນໃນຫຼັກ "person" ຄັກຫຼາຍກວ່າ 1 (ສະຖານະການຄົງທີ່ຂອງminOccursແມ່ນ 1) ແລະຫຼາຍກວ່າ 10 ຄັນ.

minOccurs ສະຖານະການ

<minOccurs> ສະຖານະການຈະກຳນົດຄວາມຫຼາຍຄັກທີ່ສາມາດປະກົດຂຶ້ນຂອງຫຼັກໄດ້:

<xs:element name="person">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="full_name" type="xs:string"/>
      <xs:element name="child_name" type="xs:string"
      maxOccurs="10" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

ບັນທັດທີ່ວ່າຫຼັກມີຫຼັກເພີ່ມ "child_name" ສາມາດປະກົດຂຶ້ນໃນຫຼັກ "person" ບໍ່ມີຄັນຫຼາຍກວ່າ 0 ຄັນ ແລະຫຼາຍກວ່າ 10 ຄັນ.

ຄຳແນະນຳ:ສຳລັບການຫຼຸດລົງຈຳນວນການປະກົດຂອງບັນດາບັນດາບັນຫາ, ຂ້ອຍຂໍ້ສະເໜີຄຳສັ່ງ maxOccurs="unbounded".

ບັນດາຄວາມທີ່ພິຈາລະນາ:

ເອກະສານ XML ຊື່ "Myfamily.xml":

<?xml version="1.0" encoding="ISO-8859-1"?>
<persons xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="family.xsd">
<person>
<full_name>Tony Smith</full_name>
<child_name>Cecilie</child_name>
</person>
<person>
<full_name>David Smith</full_name>
<child_name>Jogn</child_name>
<child_name>mike</child_name>
<child_name>kyle</child_name>
<child_name>mary</child_name>
</person>
<person>
<full_name>Michael Smith</full_name>
</person>
</persons>

ໃນເອກະສານ XML ນີ້ມີບັນດາບັນຫາ "persons" ທີ່ເປັນບັນດາບັນຫາຫຼັກ. ພາຍໃນບັນດາບັນຫາຫຼັກ "person" ນີ້ພວກເຮົາກໍານົດບັນດາ "person" ສາມບັນດາ. ແຕ່ລະ "person" ຕ້ອງມີ "full_name" ບັນດາບັນຫາ, ແລະສາມາດມີ "child_name" ບັນດາບັນຫາຈັກກັບ 5 "child_name".

ນີ້ແມ່ນເອກະສານ schema "family.xsd":

<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="persons">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="person" maxOccurs="unbounded">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="full_name" type="xs:string"/>
            <xs:element name="child_name" type="xs:string"
            minOccurs="0" maxOccurs="5"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:element>
</xs:schema>

Group indicator

Group indicator ຖືກນຳໃຊ້ເພື່ອກໍານົດຫຼັກຕົວທີ່ກ່ຽວຂ້ອງກັນ.

elementGroup

ຫຼັກຕົວຈະຖືກກໍານົດຜ່ານການອະທິບາຍ group:

<xs:group name="组名称">
  ...
</xs:group>

ທ່ານຕ້ອງຕັ້ງຄວາມສຳຄັນພາຍໃນການອະທິບາຍ group ອິນເຕີບັນຍັດ all、choice ຫຼື sequence. ບົດສະຫຼຸບນີ້ກໍານົດ group ທີ່ມີຊື່ "persongroup" ທີ່ກໍານົດກັນກັບຫຼັກຕົວຫຼາຍສິ່ງທີ່ຕ້ອງມີການປະກົດຕົວໃນການຈັດອອກທີ່ຕາຍເວົ້າ:

<xs:group name="persongroup">
  <xs:sequence>
    <xs:element name="firstname" type="xs:string"/>
    <xs:element name="lastname" type="xs:string"/>
    <xs:element name="birthday" type="xs:date"/>
  </xs:sequence>
</xs:group>

ພຽງແຕ່ຫຼັງຈາກທ່ານໄດ້ກໍານົດ group ທີ່ຫຼັງຈາກນັ້ນ ທ່ານສາມາດນຳໃຊ້ມັນໃນການກໍານົດອື່ນໆ:

<xs:group name="persongroup">
  <xs:sequence>
    <xs:element name="firstname" type="xs:string"/>
    <xs:element name="lastname" type="xs:string"/>
    <xs:element name="birthday" type="xs:date"/>
  </xs:sequence>
</xs:group>
<xs:element name="person" type="personinfo"/>
<xs:complexType name="personinfo">
  <xs:sequence>
    <xs:group ref="persongroup"/>
    <xs:element name="country" type="xs:string"/>
  </xs:sequence>
</xs:complexType>

attributeGroup

ຄູ່ມາຂອງລາຍຊື່ຈະຖືກກໍານົດຜ່ານການອະທິບາຍ attributeGroup:

<xs:attributeGroup name="组名称">
  ...
</xs:attributeGroup>

ບົດສະຫຼຸບນີ້ກໍານົດຄູ່ມາຂອງລາຍຊື່ທີ່ມີຊື່ວ່າ "personattrgroup":

<xs:attributeGroup name="personattrgroup">
  <xs:attribute name="firstname" type="xs:string"/>
  <xs:attribute name="lastname" type="xs:string"/>
  <xs:attribute name="birthday" type="xs:date"/>
</xs:attributeGroup>

ພຽງແຕ່ຫຼັງຈາກທີ່ທ່ານໄດ້ກໍານົດຄູ່ມາຂອງລາຍຊື່ຫຼັງຈາກນັ້ນ ທ່ານສາມາດນຳໃຊ້ມັນໃນການກໍານົດອື່ນໆໄດ້ ຄືກັບນັ້ນ:

<xs:attributeGroup name="personattrgroup">
  <xs:attribute name="firstname" type="xs:string"/>
  <xs:attribute name="lastname" type="xs:string"/>
  <xs:attribute name="birthday" type="xs:date"/>
</xs:attributeGroup>
<xs:element name="person">
  <xs:complexType>
    <xs:attributeGroup ref="personattrgroup"/>
  </xs:complexType>
</xs:element>