ÈçºÎʹÓà 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)>

µÚ 1 Ðж¨Òå note ÔªËØÓÐËĸö×ÓÔªËØ£º"to, from, heading, body"¡£

µÚ 2-5 Ðж¨ÒåÁË to, from, heading, body ÔªËØµÄÀàÐÍÊÇ "#PCDATA"¡£

XML Schema

ÏÂÃæÕâ¸öÀý×ÓÊÇÒ»¸öÃûΪ "note.xsd" µÄ XML Schema Îļþ£¬Ëü¶¨ÒåÁËÉÏÃæÄǸö XML ÎĵµµÄÔªËØ£º

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3school.com.cn"
xmlns="http://www.w3school.com.cn"
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.w3school.com.cn/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.w3school.com.cn"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3school.com.cn note.xsd">

<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don't forget the meeting!</body>
</note>
VUE