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

w3pop.com :: ÍøÂçѧԺ :: Schema (XSD) :: XSD - <schema>ÔªËØ

»áÔ±µÇ½

ÕʺÅ

ÃÜÂë

»Ø´ð

¼ÇסÃÜÂë

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

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 - <schema>ÔªËØ


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

The <schema> element is the root element of every XML Schema.
<schema>ÔªËØÊÇÿ·ÝXML SchemaÎļþµÄ¸ùÔªËØ¡£


The <schema> Element
<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"
targetNamespace="http://www.w3pop.com"
xmlns="http://www.w3schools.com"

elementFormDefault="qualified">
...
...
</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ʵÀýÎĵµÖÐËùʹÓõÄËùÓÐÔªËØ¶¼±ØÐëÊÇÓÐЧµÄÃüÃû¿Õ¼ä¡£


Referencing a Schema in an XML Document
ÔÚÒ»·ÝXMLÎĵµÖÐÉæ¼°Schema

This XML document has a reference to an XML Schema:
ÏÂÊöXMLÎĵµÖÐÉæ¼°µ½ÁËÒ»·ÝXML  Schiema£¬¾ßÌåÈçÏ£º

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

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"

ÆÀÂÛ (1) 1 All