Compound elements contain other elements and / or attributes. A compound element is an XML element that contains other elements and / or attributes. Empty element An element that contains other elements Elements that contain only text An element that contains elements and text 注意: All of the above elements can contain attributes! The compound element, “product”, is empty: The compound element, “employee”, contains only other elements: The compound XML element, “food”, contains only text: Compound XML elements, “description” contains elements and text: Look at this composite XML element, “employee”, which contains only other elements: In XML Schema, we have two ways to define compound elements: By naming this element, you can declare the “employee” element directly, like this: If you use the method described above, only “employee” can use the specified compound type. Notice that its child elements, “firstname” and “lastname”, are enclosed in the indicator < sequence >. You will be in the XSD 指示器 Learn more about indicators in this section. 2. “employee” 元素可以使用 type 属性,这个属性的作用是引用要使用的复合类型的名称: If you use the method described above, several elements can use the same compound type, such as this: You can also base an existing composite element on a composite element, and then add some elements, like this:What is a compound element? ¶
There are four types of compound elements: ¶
Examples of compound elements ¶
<product pid="1345"/>
<employee>
<firstname>John</firstname>
<lastname>Smith</lastname>
</employee>
<food type="dessert">Ice cream</food>
<description>
It happened on <date lang="norwegian">03.03.99</date> ....
</description>
How do you define compound elements? ¶
<employee>
<firstname>John</firstname>
<lastname>Smith</lastname>
</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>
<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>
<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>
<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>