ÍøÂçѧԺ 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-28 ä¯ÀÀ:4549 :: ::

With XML Schemas, one element can substitute another element.
ÎÒÃÇ¿ÉÒÔͨ¹ýXML SchemaʵÏÖÒ»¸öÔªËØÌæ´úÁíÒ»ÔªËØ¡£


Element Substitution
ÔªËØÌæ´ú

Let's say that we have users from two different countries: England and Norway. We would like the ability to let the user choose whether he or she would like to use the Norwegian element names or the English element names in the XML document.
¼ÙÉèÕâÀï°üº¬Á½¸ö·Ö±ðÀ´×ÔÓ¢¹úºÍŲÍþµÄʹÓÃÕߣ¬ÎÒÃÇÏ£ÍûʵÏÖÕâÑùµÄ¹¦ÄÜ£ºÁ½Î»Ê¹ÓÃÕßÄܹ»¸ù¾Ý×Ô¼ºµÄÓïÑÔÄÜÁ¦Ñ¡ÔñXMLÎĵµÖÐËùʹÓõÄŲÍþÔªËØÃû»òÓ¢ÎÄÔªËØÃû¡£

To solve this problem, we could define a substitutionGroup in the XML schema. First, we declare a head element and then we declare the other elements which state that they are substitutable for the head element.
ΪÁ˽â¾öÕâ¸öÎÊÌ⣬ÎÒÃÇÔÚXML schemaÀﶨÒåÁËÌæ´ú×é¡£Ê×ÏÈ£¬ÎÒÃÇÉùÃ÷ÁËÒ»¸ö±êÌâÔªËØ£¬È»ºó£¬ÎÒÃÇÉùÃ÷ÁËÓÃÓÚÌæ´ú±êÌâÔªËØµÄÆäËüÔªËØ£º

<xs:element name="name" type="xs:string"/>
<xs:element name="navn" substitutionGroup="name"/>

In the example above, the "name" element is the head element and the "navn" element is substitutable for "name".
ÔÚÉÏÊö°¸ÀýÖУ¬"name" ÔªËØÊDZêÌâÔªËØ£¬"navn" ÔªËØÊÇ "name" Ìæ´úÔªËØ¡£

Look at this fragment of an XML schema:
Çë¿´ÏÂÃæµÄXML schemaƬ¶Î£º

<xs:element name="name" type="xs:string"/>
<xs:element name="navn" substitutionGroup="name"/>
<xs:complexType name="custinfo">
<xs:sequence>
<xs:element ref="name"/>
</xs:sequence>
</xs:complexType>
<xs:element name="customer" type="custinfo"/>
<xs:element name="kunde" substitutionGroup="customer"/>

A valid XML document (according to the schema above) could look like this:
¸ù¾ÝÉÏÊöschemaµÄXMLÎĵµ£¬ÎÒÃǵõ½ÁË Ò»·ÝÓÐЧµÄXMLÎĵµ£¬ÈçÏÂËùʾ£º

<customer>
<name>John Smith</name>

</customer>

or like this:
»òÕßÈçÏÂËùʾ£º

<kunde>

<navn>John Smith</navn>
</kunde>

 


Blocking Element Substitution
Ëø¶¨ÔªËØÌæ´ú

To prevent other elements from substituting with a specified element, use the block attribute:
ΪÁË·ÀÖ¹ÆäËüÔªËØ±»ÒÑÖ¸¶¨µÄÔªËØÌæ´ú£¬¿ÉÒÔÓÃblock [ Ëø¶¨ ] ÊôÐÔ£º

<xs:element name="name" type="xs:string" block="substitution"/>

Look at this fragment of an XML schema:
Çë¿´ÏÂÃæÕâ¶ÎXML schemaƬ¶Î£º

<xs:element name="name" type="xs:string" block="substitution"/>

<xs:element name="navn" substitutionGroup="name"/>
<xs:complexType name="custinfo">
<xs:sequence>
<xs:element ref="name"/>

</xs:sequence>
</xs:complexType>
<xs:element name="customer" type="custinfo" block="substitution"/>
<xs:element name="kunde" substitutionGroup="customer"/>

A valid XML document (according to the schema above) looks like this:
¸ù¾ÝÉÏÊöschemaµÄXMLÎĵµ£¬ÎÒÃǵõ½ÁË Ò»·ÝÓÐЧµÄXMLÎĵµ£¬ÈçÏÂËùʾ£º

<customer>

<name>John Smith</name>
</customer>

BUT THIS IS NO LONGER VALID:
µ«ÊÇÏÂÃæÕâÑù¾Í²»ÔÙÓÐЧÁË£º

<kunde>
<navn>John Smith</navn>
</kunde>

 


Using substitutionGroup
ʹÓÃÌæ´ú×é

The type of the substitutable elements must be the same as, or derived from, the type of the head element. If the type of the substitutable element is the same as the type of the head element you will not have to specify the type of the substitutable element.
Ìæ´úÔªËØµÄÀàÐÍÓ¦¸ÃÓë±êÌâÔªËØµÄÀàÐÍÏàͬ£¬»òÊÇ´ÓÖÐÅÉÉú³öÀ´µÄ¡£Èç¹ûÌæ´úÔªËØµÄÀàÐͺͱêÌâÔªËØµÄÀàÐÍÏàͬ£¬Äã¾Í²»ÐèÒªÔÙÖ¸Ã÷Ìæ´úÔªËØµÄÀàÐÍÁË¡£

Note that all elements in the substitutionGroup (the head element and the substitutable elements) must be declared as global elements, otherwise it will not work!
×¢Òâ£ºÌæ´úÔªËØ×éÄÚµÄËùÓÐÔªËØ£¨±êÌâÔªËØºÍÌæ´úÔªËØ£©±ØÐëÉùÃ÷Ϊ“È«ÓòÔªËØ£¨global element£©”£¬·ñÔòËüÊDz»»á·¢Éú×÷Óõģ¡


What are Global Elements?
ʲôÊǓȫÓòÔªËØ”£¿

Global elements are elements that are immediate children of the "schema" element! Local elements are elements nested within other elements.
“È«ÓòÔªËØ”ÊÇ"schema"ÔªËØÏÂÃæµÄÖ±½Ó×ÓÔªËØ¡£“±¾µØÔªËØ”ÊÇǶÌ×ÔÚÆäËüÔªËØÄÚµÄÔªËØ¡£

ÆÀÂÛ (0) All