XSD’dan foydalanish
XML hujjatlar DTD’ga yoki XML sxemasiga havolaga ega bo‘lishi mumkin.
Oddiy XML hujjat
"note.xml" deb nomlangan ushbu oddiy XML hujjatga qarang:
<?xml version="1.0"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>DTD fayli
Quyidagi misol yuqoridagi XML hujjat ("note.xml") elementlarini aniqlaydigan "note.dtd" nomli DTD fayli:
<!ELEMENT note (to, from, heading, body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>Birinchi qator note elementida to‘rtta bola element bo‘lishini belgilaydi: "to, from, heading, body".
2–5-qatorlar to, from, heading, body elementlarini "#PCDATA" tipida deb belgilaydi.
XML sxemasi
Quyidagi misol yuqoridagi XML hujjat ("note.xml") elementlarini aniqlaydigan "note.xsd" nomli XML Schema fayli:
<?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>note elementi murakkab tip (complex type), chunki u boshqa elementlarni o‘z ichiga oladi. Boshqa elementlar (to, from, heading, body) esa oddiy tiplar (simple types), chunki ular boshqa elementlarni o‘z ichiga olmaydi. Oddiy va murakkab tiplar haqida keyingi boblarda batafsil bilib olasiz.
DTD’ga havola
Bu XML hujjatda DTD’ga havola bor:
<?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 sxemasiga havola
Bu XML hujjatda XML sxemasiga havola bor:
<?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>W3Schools Pathfinder
Yutuqlaringizni kuzating – bu bepul!
