w3pop.com :: ÍøÂçѧԺ :: Schema (XSD) :: XSD - <schema>ÔªËØ
XSD - <schema>ÔªËØ
::
The <schema> element is the root element of every XML Schema.
<schema>ÔªËØÊÇÿ·ÝXML SchemaÎļþµÄ¸ùÔªËØ¡£
The <schema> element is the root element of every XML Schema:
<schema>ÔªËØÊÇÿ·ÝXML SchemaÎļþµÄ¸ùÔªËØ¡£
<?xml version="1.0"?> <xs:schema> ... </xs:schema> |
The <schema> element may contain some attributes. A schema declaration often looks something like this:
<schema>ÔªËØÒ²¿ÉÒÔ°üº¬Ò»Ð©ÊôÐÔ¡£Ò»¸öschemaÉùÃ÷ͨ³£»á°´ÕÕÏÂÊö·½Ê½Êéд£º
<?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" ... </xs:schema> |
The following fragment:
¿´ÏÂÊöƬ¶Î£º
xmlns:xs="http://www.w3.org/2001/XMLSchema" |
indicates that the elements and data types used in the schema come from the "http://www.w3.org/2001/XMLSchema" namespace. It also specifies that the elements and data types that come from the "http://www.w3.org/2001/XMLSchema" namespace should be prefixed with xs:
ÉÏÊö°¸ÀýÖ¸Ã÷ÁË£ºÔÚschemaÖÐʹÓõÄÔªËØºÍÊý¾ÝÀàÐÍÀ´×ÔÓÚ“http://www.w3.org/2001/XMLSchema”ÃüÃû¿Õ¼ä¡£ËüÒ²Ö¸¶¨ÁËÀ´×ÔÓÚ"http://www.w3.org/2001/XMLSchema"ÃüÃû¿Õ¼äµÄÔªËØºÍÊý¾ÝÀàÐͱØÐ븽´øÇ°×º“xs:”¡£
This fragment:
¸ÃƬ¶ÎÈçÏ£º
targetNamespace="http://www.w3pop.com" |
indicates that the elements defined by this schema (note, to, from, heading, body.) come from the "http://www.w3schools.com" namespace.
ÉÏÊö°¸ÀýÖ¸Ã÷ÁË£ºÓÉÕâ·Ýschema(note¡¢to¡¢from¡¢heading¡¢body)¶¨ÒåµÄÔªËØÀ´×ÔÓÚ"http://www.w3pop.com"ÃüÃû¿Õ¼ä¡£
This fragment:
¸ÃƬ¶ÎÈçÏ£º
xmlns="http://www.w3pop.com" |
indicates that the default namespace is http://www.w3pop.com.
ÉÏÊö°¸ÀýÖ¸Ã÷ÁË£ºÄ¬ÈÏÃüÃû¿Õ¼äÊÇhttp://www.w3pop.com.
This fragment:
¸ÃƬ¶ÎÈçÏ£º
elementFormDefault="qualified" |
indicates that any elements used by the XML instance document which were declared in this schema must be namespace qualified.
ÉÏÊö°¸ÀýÖ¸Ã÷ÁË£ºÔÚÕâ·ÝÓÉschemaÉùÃ÷µÄXMLʵÀýÎĵµÖÐËùʹÓõÄËùÓÐÔªËØ¶¼±ØÐëÊÇÓÐЧµÄÃüÃû¿Õ¼ä¡£
This XML document has a reference to an XML Schema:
ÏÂÊöXMLÎĵµÖÐÉæ¼°µ½ÁËÒ»·ÝXML Schiema£¬¾ßÌåÈçÏ£º
<?xml version="1.0"?> <note xmlns="http://www.w3schools.com" <to>Tove</to> |
The following fragment:
ÏÂÊöƬ¶Ï£º
xmlns="http://www.w3schools.com" |
specifies the default namespace declaration. This declaration tells the schema-validator that all the elements used in this XML document are declared in the "http://www.w3schools.com" namespace.
ÉÏÊö°¸ÀýÖ¸¶¨ÁË£ºÄ¬ÈϵÄÃüÃû¿Õ¼äÉùÃ÷¡£¸ÃÉùÃ÷¸æËßschema¼ìÑéÆ÷ÏÂÊöÐÅÏ¢£ºÕâ·ÝXMLÎĵµÖÐʹÓõÄËùÓÐÔªËØ¶¼ÔÚhttp://www.w3pop.comµÄÃüÃû¿Õ¼äÖÐÉùÃ÷¹ý¡£
Once you have the XML Schema Instance namespace available:
ÏÖÔÚ£¬ÄãÒѾӵÓÐÁË¿ÉÒÔʹÓõÄXML Schema°¸ÀýÃüÃû¿Õ¼ä£¬¾ßÌåÈçÏ£º
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
you can use the schemaLocation attribute. This attribute has two values. The first value is the namespace to use. The second value is the location of the XML schema to use for that namespace:
Äã¿ÉÒÔʹÓÃSchemaLocationÊôÐÔ¡£Õâ¸öÊôÐÔ°üº¬Á½¸öÖµ£ºµÚÒ»¸öÖµ±íʾÐèҪʹÓõÄÃüÃû¿Õ¼ä£»µÚ¶þ¸öÖµ±íʾΪÃüÃû¿Õ¼äÖ¸¶¨ÁËÆäÔÚXML schemaÖеľßÌåλÖãº
xsi:schemaLocation="http://www.w3schools.com note.xsd" |