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

A complex element contains other elements and/or attributes.
Ò»¸ö¸´ºÏÔªËØ°üº¬ÆäËüÔªËØºÍ / »òÊôÐÔ¡£


What is a Complex Element?
ʲôÊǸ´ºÏÔªËØ£¿

A complex element is an XML element that contains other elements and/or attributes.
¸´ºÏÔªËØÊǰüº¬ÆäËüÔªËØºÍ / »òÊôÐÔµÄXMLÔªËØ£º

There are four kinds of complex elements:
ÏÂÃæÁоÙËÄÖÖ¸´ºÏÔªËØ£º

  • empty elements
    ¿ÕÔªËØ
  • elements that contain only other elements
    Ö»°üº¬ÆäËüÔªËØµÄÔªËØ
  • elements that contain only text
    Ö»°üº¬Îı¾µÄÔªËØ
  • elements that contain both other elements and text
    °üº¬Îı¾ºÍÆäËüÔªËØµÄÔªËØ

Note: Each of these elements may contain attributes as well!
×¢Ò⣺ÉÏÊöÿ¸öÔªËØÖпÉÄÜ»¹°üº¬ÊôÐÔ£¡


Examples of Complex Elements
¸´ºÏÔªËØ°¸Àý

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>
<firstname>John</firstname>
<lastname>Smith</lastname>
</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>

It happened on <date lang="norwegian">03.03.99</date> ....
</description>

 


How to Define a Complex Element
¸´ºÏÔªËØµÄ¶¨Òå·½·¨

Look at this complex XML element, "employee", which contains only other elements:
ÏÈÇë¿´¿´ÏÂÃæÕâ¸öÖ»°üº¬ÆäËüÔªËØµÄ¸´ºÏXMLÔªËØ"employee"£º

<employee>
<firstname>John</firstname>
<lastname>Smith</lastname>

</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">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>

<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>

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

<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>

</xs:sequence>
</xs:complexType>

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:element name="student" type="personinfo"/>
<xs:element name="member" type="personinfo"/>
<xs:complexType name="personinfo">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>

</xs:sequence>
</xs:complexType>

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:sequence>
<xs:element name="firstname" type="xs:string"/>

<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="fullpersoninfo">

<xs:complexContent>
<xs:extension base="personinfo">
<xs:sequence>
<xs:element name="address" type="xs:string"/>

<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>

</xs:extension>
</xs:complexContent>
</xs:complexType>

ÆÀÂÛ (0) All