XSD အသုံးပြုခြင်း

XML ဖိုင် သည် DTD သို့မဟုတ် XML Schema ကို ကိုးကွယ်နိုင်သည်。

အကြမ်းအားစား XML ဖိုင်:

အမည် "note.xml" ရှိ ဒီ XML ဖိုင် ကို ကြည့်ပါ:

<?xml version="1.0"?>
<note>
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don't forget the meeting!</body>
</note>

DTD ဖိုင်

အောက်ပါ အမည် "note.dtd" ရှိ ဒီ DTD ဖိုင် သည် အထက်တွင် ဖော်ပြထားသော XML ဖိုင် အစုအဖွဲ့ ကို အသုံးပြုသည်:

<!ELEMENT note (to, from, heading, body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>

note အစားသောက် အာရှိုက် သည် နှစ်ပုံး အစုအဖွဲ့ တွင် ပါဝင်သည်: "to, from, heading, body"。

တစ် ပုံနှစ် ၂-၅ ကြိမ် တွင် to, from, heading, body အအုပ် အကျယ်အဝန်း အအုပ် အမည်များ သည် "#PCDATA" ဖြစ်သည် အဖြစ် အသုံးပြုပါသည်။

XML Schema

အောက်ပါ နည်းပါး သည် "note.xsd" အမည်ရှိ သတင်းအချက် အတိုင်း အရေးကြီး ဖြစ်ပါသည် အားဖြင့် အခြေခံ XML Schema ဖြစ်သည်:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.codew3c.com"
xmlns="http://www.codew3c.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>

note အအုပ် သည် အပိုစိတ် အအုပ် ဖြစ်သည် သည့်ကြောင့်ဖြစ်ပါသည်။ အပိုစိတ် အအုပ် (to, from, heading, body) သည် အကျယ်အဝန်း အအုပ် ဖြစ်သည် သည့်ကြောင်းဖြစ်ပါသည်။ အပိုစိတ် အအုပ် နှင့် အကျယ်အဝန်း အအုပ် အကြောင်းကို အောက်ပါ စာမျက်နှာများ တွင် အော်မေးမြန်းပါလိမ့်မည်။

DTD အတွက် ကိုးကားခြင်း

ဒီ ဖိုင် သည် DTD အတွက် ကိုးကားခြင်း ပါဝင်သည်:

<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "http://www.codew3c.com/dtd/note.dtd">
<note>
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don't forget the meeting!</body>
</note>

XML Schema အတွက် ကိုးကားခြင်း

ဒီ ဖိုင် သည် XML Schema အတွက် ကိုးကားခြင်း ပါဝင်သည်:

<?xml version="1.0"?>
<note
xmlns="http://www.codew3c.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.codew3c.com note.xsd">
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don't forget the meeting!</body>
</note>