XSD ဘယ်လိုလုပ်ရမလဲ။
XML စာရွက်စာတမ်းများတွင် DTD သို့မဟုတ် XML Schema ကိုကိုးကားနိုင်သည်။
ရိုးရှင်းသော XML စာရွက်စာတမ်း
"note.xml" ဟုခေါ်သော ဤရိုးရှင်းသော XML စာရွက်စာတမ်းကိုကြည့်ပါ-
<?xml version="1.0"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
DTD ဖိုင်တစ်ခု
အောက်ဖော်ပြပါ ဥပမာသည် အထက်ဖော်ပြပါ XML စာရွက်စာတမ်း၏ ဒြပ်စင်များကို သတ်မှတ်ပေးသည့် "note.dtd" ဟုခေါ်သော DTD ဖိုင်တစ်ခုဖြစ်သည် ("note.xml"):
<!ELEMENT note (to, from, heading, body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
ပထမစာကြောင်းတွင် ကလေးဒြပ်စင်လေးခုပါရှိသည်- "to, from, heading, body" ကို သတ်မှတ်သည်။
စာကြောင်း 2-5 သည် "#PCDATA" အမျိုးအစားအဖြစ် to, from, heading, body element ကို သတ်မှတ်သည်။
XML Schema သို့
အောက်ဖော်ပြပါ ဥပမာသည် အထက်ဖော်ပြပါ XML စာရွက်စာတမ်း၏ အစိတ်အပိုင်းများကို သတ်မှတ်ပေးသည့် "note.xsd" ဟုခေါ်သော XML Schema ဖိုင်တစ်ခုဖြစ်သည်):
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="https://www.w3schools.com"
xmlns="https://www.w3schools.com"
elementFormDefault="qualified">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
မှတ်စုဒြပ်စင်သည် အခြားဒြပ်စင်များပါ၀င်သောကြောင့် ရှုပ်ထွေးသောအမျိုးအစားဖြစ်သည် ။ အခြားဒြပ်စင်များ (to, from, heading, body) များသည် အခြားဒြပ်စင်များမပါဝင်သောကြောင့် ရိုးရိုးအမျိုးအစားများ ဖြစ်သည်။ အောက်ပါအခန်းများတွင် ရိုးရှင်းပြီး ရှုပ်ထွေးသောအမျိုးအစားများအကြောင်း ပိုမိုလေ့လာနိုင်မည်ဖြစ်သည်။
DTD ကိုကိုးကား
ဤ XML စာရွက်စာတမ်းတွင် DTD ကို ကိုးကားချက်ပါရှိသည်။
<?xml version="1.0"?>
<!DOCTYPE note SYSTEM
"https://www.w3schools.com/xml/note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
XML Schema ကိုးကား
ဤ XML စာရွက်စာတမ်းတွင် XML Schema ကို ကိုးကားပါရှိသည်-
<?xml version="1.0"?>
<note
xmlns="https://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://www.w3schools.com/xml note.xsd">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>