w3pop.com :: ÍøÂçѧԺ :: Schema (XSD) :: ÈçºÎ¶¨ÖÆ XSD
XML documents can have a reference to a DTD or to an XML Schema.
XMLÎĵµ¿ÉÒÔÓëÒ»·ÝDTD»òXML SchemaÏà¹ØÁª¡£
Look at this simple XML document called "note.xml":
Çë¿´ÏÂÃæÒ»·ÝÃûΪ"note.xml"µÄ¼òÒ×XMLÎĵµ£º
<?xml version="1.0"?> |
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)> |
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”ËĸöÔªËØ¡£
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:element name="note"> </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£©£¬ÒòΪËü²»°üº¬ÆäËüÔªËØ¡£ÔÚÏÂÃæµÄ¼¸ÕÂÖУ¬Äã»áѧϰ¸ü¶à¹ØÓÚ¼òµ¥ÀàÐͺ͸´ºÏÀàÐ͵ÄÏà¹ØÖªÊ¶¡£
This XML document has a reference to a DTD:
ÏÂÊöÕâ·ÝXMLÎĵµÓëDTDÏà¹Ø£º
<?xml version="1.0"?> <!DOCTYPE note SYSTEM <note> |
This XML document has a reference to an XML Schema:
ÏÂÊöÕâ·ÝXMLÎĵµÓëXML SchemaÏà¹Ø£º
<?xml version="1.0"?> <note |
ÆÀÂÛ (0)
All