XSD ပေါင်းစပ် အရာ

ပေါင်းစပ်သည့်အရာ သည် အရာများ နှင့် အချက်အလက် ပါဝင်သည့် အရာဖြစ်သည်。

ပေါင်းစပ်သည့်အရာ မှာ အမှတ်အသားများကို ဘဲကြိုးသို့မဟုတ်မည်မဟုတ်?

ပေါင်းစပ်သည့်အရာ သည် အရာများ နှင့် အချက်အလက် ပါဝင်သည့် XML အရာဖြစ်သည်。

ပေါင်းစပ်သည့်အရာ နှစ်မျိုး အပါအဝင် ဖြစ်သည်:

  • မမှုပါသည့် အရာ
  • အရာများ ပါဝင်သည့် အရာ
  • သာ စကားလုံး ပါဝင်သည့် အရာ
  • အရာများ နှင့် စကားလုံး ပါဝင်သည့် အရာ

အကြောင်းအရာအရာတိုင်း ကို ရှိခြင်းဖြင့် ဖော်ထုတ်နိုင်သည်!

ပေါင်းစပ်သည့်အရာ အမျိုးအစား

ပေါင်းစပ်သည့်အရာ "product" တွင် သာ မမှုပါသည်:

<product pid="1345"/>

ပေါင်းစပ်သည့်အရာ "employee" တွင် သာ အရာများ ပါဝင်သည်:

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

ပေါင်းစပ်သည့်အရာ "food" တွင် သာ စကားလုံး ပါဝင်သည်:

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

ပေါင်းစပ်သည့်အရာ "description" တွင် အရာများ နှင့် စကားလုံး ပါဝင်သည်:

<description>
ယူနက်ယျင်း မေလ ၃၀ရက် ၉၉ခုနှစ် ဖြစ်ပွားခဲ့သည်မှာ ...
</description>

တွေးခေါ်ရန် ပေါင်းစပ်သည့်အရာကို ဘဲကြိုးသို့မဟုတ်မည်မဟုတ်?

အပေါင်းစု XML ကို ကြည့်ပါ။ "employee" အပေါင်းစု ကို အသုံး ပြု သည်။ အခြား အပေါင်းစု တွေ ကို အသုံး ပြု သည်။

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

XML Schema တွင် ကိုယ်စားပြု အပေါင်းစု ကို အသုံး ပြု ရန် အခြား နည်းလမ်း တစ် ခု နှင့် နည်းလမ်း တစ် ခု ရှိ သည်။

1. အပေါင်းစု အမည် ကို ထို့ကဲ့သို့ အသုံး ပြု ပြီး "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" ကို အခြေခံ အပေါင်းစု ကို အသုံး ပြု နိုင် ပါ။ အခြေခံ အပေါင်းစု အဖြစ် အသုံး ပြု သော "firstname" နှင့် "lastname" အပေါင်းစု ကို အခြေခံ အပေါင်းစု <sequence> အရွယ် အရေးဆို ပါ။ အခြေခံ အပေါင်းစု ကို အသုံး ပြု သည်။ 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>