ÍøÂçѧԺ w3popÉçÇø ÍøÂç×ÊÔ´ ITÐÂÎÅ

w3pop.com :: ÍøÂçѧԺ :: Schema (XSD) :: ÈçºÎ¶¨ÖÆ XSD

»áÔ±µÇ½

ÕʺÅ

ÃÜÂë

»Ø´ð

¼ÇסÃÜÂë

Íü¼ÇÃÜÂë? ×¢²á

Schema (XSD)
Schema (XSD) ½éÉ..
ΪºÎʹÓà XML Sch..
ÈçºÎ¶¨ÖÆ XSD
XSD - <schema..
XSD ¼òµ¥ÔªËØ
XSD ÊôÐÔ
XSD Ô¼ÊøÃæ
XSD ¸´ºÏÔªËØ
XSD ¸´ºÏ¿ÕÔªËØ
XSD ¸´ºÏ´¿ÔªËØ
XSD ¸´ºÏ´¿Îı¾
XSD »ìºÏÄÚÈݵĸ´..
XSD ָʾÆ÷¸´ºÏÀà..
XSD <any> ..
XSD <anyAttri..
XSD ÔªËØÌæ´ú
XSD ʵÀý
XSD ×Ö·û´®Êý¾ÝÀà..
XSD ÈÕÆÚÊý¾ÝÀàÐÍ
XSD СÊýÊý¾ÝÀàÐÍ

ÈçºÎ¶¨ÖÆ XSD


×÷Õß:w3pop.com ·­Òë/ÕûÀí:w3pop.com ·¢²¼:2007-04-29 ÐÞ¸Ä:2007-08-27 ä¯ÀÀ:5410 :: ::

XML documents can have a reference to a DTD or to an XML Schema.
XMLÎĵµ¿ÉÒÔÓëÒ»·ÝDTD»òXML SchemaÏà¹ØÁª¡£


A Simple XML Document
Ò»·Ý¼òµ¥µÄXMLÎĵµ

Look at this simple XML document called "note.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>

 


A DTD File
Ò»·ÝDTDÎļþ

The following example is a DTD file called "note.dtd" that defines the elements of the XML document above ("note.xml"):
ÏÂÊö°¸ÀýÁоÙÁËÃûΪ"note.dtd"µÄDTDÎļþ£¬Ëü¶¨ÒåÁËÉÏÊöXMLÎĵµ("note.xml")ÖеÄÔªËØ£º

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

The first line defines the note element to have four child elements: "to, from, heading, body".
µÚÒ»Ðж¨ÒåÁ˰üº¬“to¡¢from¡¢heading¡¢body”Ëĸö×ÓÔªËØµÄ“note”ÔªËØ¡£

Line 2-5 defines the to, from, heading, body elements to be of type "#PCDATA".
µÚ2µ½5Ðж¨ÒåÁË"#PCDATA"ÀàÐ͵ēto¡¢from¡¢heading¡¢body”ËĸöÔªËØ¡£


An XML Schema
Ò»·ÝXML Schema

The following example is an XML Schema file called "note.xsd" that defines the elements of the XML document above ("note.xml"):
ÏÂÊö°¸ÀýÖУ¬Ò»¸öÃûΪ"note.xsd"µÄXML SchemaÎļþ¶¨ÒåÁËÉÏÊöXMLÎĵµ£¨"note.xml"£©ÖеÄÔªËØ£º

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"

xmlns="http://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>

The note element is a complex type because it contains other elements. The other elements (to, from, heading, body) are simple types because they do not contain other elements. You will learn more about simple and complex types in the following chapters.
NoteÔªËØÊǸ´ºÏÀàÐÍ£¨complex type£©ÒòΪËü°üº¬ÁËÆäËüÔªËØ£»ÆäËüÔªËØ£¨to¡¢rom¡¢heading¡¢ body£©ÊôÓÚ¼òµ¥ÀàÐÍ£¨simple type£©£¬ÒòΪËü²»°üº¬ÆäËüÔªËØ¡£ÔÚÏÂÃæµÄ¼¸ÕÂÖУ¬Äã»áѧϰ¸ü¶à¹ØÓÚ¼òµ¥ÀàÐͺ͸´ºÏÀàÐ͵ÄÏà¹ØÖªÊ¶¡£


A Reference to a DTD
ÓëDTDÏà¹Ø

This XML document has a reference to a DTD:
ÏÂÊöÕâ·ÝXMLÎĵµÓëDTDÏà¹Ø£º

<?xml version="1.0"?>
<!DOCTYPE note SYSTEM
"http://www.w3schools.com/dtd/note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>

<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

 


A Reference to an XML Schema
ÓëXML SchemaÏà¹Ø

This XML document has a reference to an XML Schema:
ÏÂÊöÕâ·ÝXMLÎĵµÓëXML SchemaÏà¹Ø£º

<?xml version="1.0"?>
<note
xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com note.xsd">

<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>

</note>

ÆÀÂÛ (0) All