15.2.9. XSD compound element

发布时间 : 2025-10-25 13:35:24 UTC      

Page Views: 10 views

Compound elements contain other elements and / or attributes.

What is a compound element?

A compound element is an XML element that contains other elements and / or attributes.

There are four types of compound elements:

  • 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!

Examples of compound elements

The compound element, “product”, is empty:

<product pid="1345"/> 

The compound element, “employee”, contains only other elements:

<employee> <firstname>Johnfirstname> <lastname>Smithlastname> employee>    

The compound XML element, “food”, contains only text:

<food type="dessert">Ice creamfood>    

Compound XML elements, “description” contains elements and text:

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

How do you define compound elements?

Look at this composite XML element, “employee”, which contains only other elements:

<employee> <firstname>Johnfirstname> <lastname>Smithlastname> employee>    

In XML Schema, we have two ways to define compound elements:

  1. By naming this element, you can declare the “employee” element directly, like this:

<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 “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 属性,这个属性的作用是引用要使用的复合类型的名称:

<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 use the same compound type, such as 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 an existing composite element on a composite element, and then 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>      
                
                
            
        
        
《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。