ບອກວ່າຈະນຳໃຊ້ XSD?

XML ບັນຊີສາມາດການອ້າງຄວາມຂອງ DTD ຫຼື XML Schema:

XML ບັນຊີທີ່ງາມຫນັງ:

ບັນຊີ "note.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)>

ຈຸດ 1 ກໍານົດສະມາຊິກ note ມີສະມາຊິກລູກສີ່: "to, from, heading, body".

ຈຸດ 2-5 ຂອງວັດສະນະນະພາບການຍັງຄົງໃນລະບົບ #PCDATA.

XML Schema

ຕົວຢ່າງດັ່ງກ່າວນີ້ແມ່ນເອກະສານ XML Schema ຊື່ "note.xsd" ທີ່ກໍານົດສະມາຊິກຂອງເອກະສານ XML ທີ່ມີກ່ອນ:

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