w3pop.com :: ÍøÂçѧԺ :: Schema (XSD) :: XSD ¸´ºÏÔªËØ
A complex element contains other elements and/or attributes.
Ò»¸ö¸´ºÏÔªËØ°üº¬ÆäËüÔªËØºÍ / »òÊôÐÔ¡£
A complex element is an XML element that contains other elements and/or attributes.
¸´ºÏÔªËØÊǰüº¬ÆäËüÔªËØºÍ / »òÊôÐÔµÄXMLÔªËØ£º
There are four kinds of complex elements:
ÏÂÃæÁоÙËÄÖÖ¸´ºÏÔªËØ£º
Note: Each of these elements may contain attributes as well!
×¢Ò⣺ÉÏÊöÿ¸öÔªËØÖпÉÄÜ»¹°üº¬ÊôÐÔ£¡
A complex XML element, "product", which is empty:
ÏÂÃæÁоÙÁËÒ»¸ö¿Õ¸´ºÏXMLÔªËØ“product”£º
<product pid="1345"/> |
A complex XML element, "employee", which contains only other elements:
Ö»°üº¬ÆäËüÔªËØµÄ¸´ºÏXMLÔªËØ“employee”£º
<employee> |
A complex XML element, "food", which contains only text:
Ö»°üº¬Îı¾µÄ¸´ºÏXMLÔªËØ"food"£º
<food type="dessert">Ice cream</food> |
A complex XML element, "description", which contains both elements and text:
°üº¬ÔªËغÍÎı¾µÄ¸´ºÏXMLÔªËØ"description"£º
<description> |
Look at this complex XML element, "employee", which contains only other elements:
ÏÈÇë¿´¿´ÏÂÃæÕâ¸öÖ»°üº¬ÆäËüÔªËØµÄ¸´ºÏXMLÔªËØ"employee"£º
<employee> |
We can define a complex element in an XML Schema two different ways:
ÎÒÃÇ¿ÉÒÔʹÓÃÁ½ÖÖ²»Í¬µÄ·½·¨ÔÚÒ»·ÝXML SchemaÎĵµÀﶨÒåÒ»¸ö¸´ºÏÔªËØ£º
1. The "employee" element can be declared directly by naming the element, like this:
1. "employee"ÔªËØ¿ÉÒÔÖ±½Óͨ¹ýÎªÔªËØÃüÃûµÄ·½Ê½±»ÉùÃ÷£¬ÈçÏÂËùʾ£º
<xs:element name="employee"> |
If you use the method described above, only the "employee" element can use the specified complex type. Note that the child elements, "firstname" and "lastname", are surrounded by the <sequence> indicator. This means that the child elements must appear in the same order as they are declared. You will learn more about indicators in the XSD Indicators chapter.
Èç¹ûÄãÓÃÁËÉÏÊö·½·¨£¬ÄÇôֻÓÐ"employee"ÔªËØ²Å¿ÉÒÔʹÓÃÖ¸¶¨µÄ¸´ºÏÀàÐÍ¡£×¢Ò⣺×ÓÔªËØ"firstname" ºÍ "lastname"ÊDZ»°üΧÔÚ“<sequence>ָʾÆ÷”ÔªËØÀïµÄ¡£ÕâÒâζ×Å£¬×ÓÔªËØ±ØÐëÒÔËüÃDZ»ÉùÃ÷µÄ˳Ðò³öÏÖ¡£ÔÚ½²ÊöXSDָʾÆ÷µÄÕ½ÚÖУ¬Äã¿ÉÒÔѧµ½¹ØÓÚָʾÆ÷¸ü¶à֪ʶ¡£
2. The "employee" element can have a type attribute that refers to the name of the complex type to use:
2. "employee"ÔªËØ¿ÉÒÔ°üº¬Ò»¸öÀàÐÍÊôÐÔ£¬ÓÃÓÚÖ¸¶¨ÐèҪʹÓõĸ´ºÏÀàÐÍÃû³Æ£º
<xs:element name="employee" type="personinfo"/> <xs:complexType name="personinfo"> |
If you use the method described above, several elements can refer to the same complex type, like this:
Èç¹ûÄãʹÓÃÉÏÊö·½·¨£¬¼¸¸öÔªËØ¿ÉÒÔÒýÓÃÏàͬµÄ¸´ºÏÀàÐÍ£¬ÈçÏÂËùʾ£º
<xs:element name="employee" type="personinfo"/> <xs:complexType name="personinfo"> |
You can also base a complex element on an existing complex element and add some elements, like this:
ÄãÒ²¿ÉÒÔÔÚÏÖÓеĸ´ºÏÔªËØµÄ»ù´¡ÉÏÔÙ¼ÓÉÏÒ»¸ö¸´ºÏÔªËØ£¬²¢Ìí¼ÓһЩÆäËüÔªËØ£¬ÈçÏÂËùʾ£º
<xs:element name="employee" type="fullpersoninfo"/> <xs:complexType name="personinfo"> <xs:complexType name="fullpersoninfo"> |
ÆÀÂÛ (0)
All