XSD ປ່ອງຄວາມລະອຽດ

ຫົວຂໍ້ປະກອບສະບາຍກວມເອົາປະກອບສັບສິນອື່ນໆແລະ/ຫລືປະສົມປະສານ:

ຫົວຂໍ້ປະກອບສະບາຍແມ່ນຫຍັງ?

ຫົວຂໍ້ປະກອບສະບາຍແມ່ນ XML ປະກອບສັບສິນທີ່ບັນຈຸປະກອບສັບສິນແລະ/ຫລືປະສົມປະສານ:

ມີສີ່ຕົວເຫຼືອຫົວຂໍ້ປະກອບສະບາຍ:

  • ປະກອບສັບສິນທີ່ບໍ່ມີຫຍັງ:
  • ປະກອບສັບສິນທີ່ບັນຈຸປະກອບສັບສິນອື່ນໆ:
  • ປະກອບສັບສິນທີ່ບັນຈຸປະກອບສັບສິນພຽງພໍ:
  • ປະກອບສັບສິນທີ່ບັນຈຸປະກອບສັບສິນແລະຂັດສະນະ:

ຄຳເຫັນ:ປະກອບສັບສິນທັງໝົດສາມາດກວມປະສົມປະສານຫາຍ!

ບົດສະຫຼຸບຫົວຂໍ້ປະກອບສະບາຍ

ຫົວຂໍ້ປະກອບສະບາຍ"product"ບໍ່ມີຫຍັງ:

<product pid="1345"/>

ຫົວຂໍ້ປະກອບສະບາຍ"employee"ບັນຈຸປະກອບສັບສິນອື່ນໆພຽງພໍ:

<employee>
<firstname>John</firstname>
<lastname>Smith</lastname>
</employee>

ຫົວຂໍ້ປະກອບສະບາຍ"food"ບັນຈຸປະກອບສັບສິນພຽງພໍ:

<food type="dessert">Ice cream</food>

ຫົວຂໍ້ປະກອບສະບາຍ"description"ບັນຈຸປະກອບຂອງສັບສິນແລະຂັດສະນະ:

<description>
ມັນໄດ້ເກີດຂຶ້ນໃນ <date lang="norwegian">03.03.99</date> ....
</description>

ພວກເຮົາຈະອະທິບາຍວ່າຫົວຂໍ້ປະກອບສະບາຍຫນັງຫນົກຫນົງ?

ບັນຍາຍຄົນປະກອບ XML "employee" ນີ້ຈະມີສັນສິນອື່ນໃນຂອງມັນ:

<employee>
<firstname>John</firstname>
<lastname>Smith</lastname>
</employee>

ໃນ XML Schema ພວກເຮົາມີສອງວິທີທີ່ສາມາດພົບປະກອບສັນສິນຄົນ:

1. ການບັນທຶກຊື່ສັນສິນ "employee" ສາມາດປະກອບສັນສິນ "employee" ດັ່ງນີ້:

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

ຖ້າທ່ານໃຊ້ວິທີທີ່ຖືກອະທິບາຍຂ້າງວາງນີ້ ແລ້ວ ແຕ່ "employee" ສາມາດໃຊ້ຄົນປະກອບສັນສິນທີ່ກໍານົດກ່ອນ: XSD ສັນສິນ ນີ້ເປັນການຮຽນຂໍ້ພາກສາຂອງສັນສິນ XSD.

2. "employee" ສັນສິນສາມາດໃຊ້ບັນດາຄຸນນະພາບ type ເພື່ອກ່ຽວຂ້ອງກັບຊື່ຄົນປະກອບສັນສິນທີ່ຈະໃຊ້:

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

ຖ້າທ່ານໃຊ້ວິທີທີ່ຖືກອະທິບາຍຂ້າງວາງນີ້ ແລ້ວ ຈະມີປະກອບສັນສິນຫຼາຍອັນທີ່ສາມາດໃຊ້ຄົນປະກອບສັນສິນດຽວກັນ ເຊັ່ນນີ້:

<xs:element name="employee" type="personinfo"/>
<xs:element name="student" type="personinfo"/>
<xs:element name="member" type="personinfo"/>
<xs:complexType name="personinfo">
  <xs:sequence>
    <xs:element name="firstname" type="xs:string"/>
    <xs:element name="lastname" type="xs:string"/>
  </xs:sequence>
</xs:complexType>

ທ່ານສາມາດບຸກລະດັບສັນສິນທີ່ມີການສ້າງຫຼັງກ່ອນ ແລະ ສົ່ງມັນໃຫ້ການສ້າງສັນສິນອື່ນໃນທາງນີ້:

<xs:element name="employee" type="fullpersoninfo"/>
<xs:complexType name="personinfo">
  <xs:sequence>
    <xs:element name="firstname" type="xs:string"/>
    <xs:element name="lastname" type="xs:string"/>
  </xs:sequence>
</xs:complexType>
<xs:complexType name="fullpersoninfo">
  <xs:complexContent>
    <xs:extension base="personinfo">
      <xs:sequence>
        <xs:element name="address" type="xs:string"/>
        <xs:element name="city" type="xs:string"/>
        <xs:element name="country" type="xs:string"/>
      </xs:sequence>
    </xs:extension>
  </xs:complexContent>
</xs:complexType>