XSD အပေါင်း အကွက် အမှတ်

通过指示器,我们可以控制在文档中使用元素的方式。

指示器

有七种指示器:

Order 指示器:

  • All
  • Choice
  • Sequence

Occurrence 指示器:

  • maxOccurs
  • minOccurs

Group 指示器:

  • Group name
  • attributeGroup name

Order 指示器

Order 指示器用于定义元素的顺序。

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 ကြိမ် ပေါ်ပေါက်နိုင်သည် (အတိုင်း အားလျော် အသုံးပြုသည် 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" ဖော်ပြချက် အသုံးပြုပါ:

အခုအခါ အကျယ်းတာ အစားအလာ...

"Myfamily.xml" အမည်ရှိ 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" ကို အသုံးပြုသည်။ အခြေခံ အမှတ် "persons" အတွင်းတွင် အသုံးပြုထားသော "person" အမှတ် ၃ ခု ရှိသည်။ ခုခု "person" အမှတ်သည် အခြေခံ အမှတ် "full_name" ကို သို့မဟုတ် ၅ ခုထိ ပါဝင်နိုင်သော "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 အမှတ်သုံး

Group အမှတ်သုံးသည် ချိတ်ဆက်ထားသော အကြောင်းအရာ အစုအဝေး အား အသိအမှတ်ပြုရန် အသုံးပြုသည်。

အစားအစာ အုပ်စု

အစားအစာ အုပ်စု ကို group အမိန့် ဖြင့် သတ်မှတ်ကြသည်:

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

သင်သည် group အမိန့် အတွင်းမှာ အရေးပါ အစားအစာ အုပ်စု သို့မဟုတ် အဆင့်သတ်ချက် သို့မဟုတ် sequence အစားအစာ ကို သတ်မှတ် ပေးသင့်သည်။ အောက်ပါ အမည်ဖြင့် "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 အမိန့် ဖြင့် သတ်မှတ်ကြသည်:

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