15.2.9. XSD compound element

发布时间 :2025-10-25 12:23:25 UTC      

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

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

<food type="dessert">Ice cream</food>

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

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

How do you define compound elements?

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

<employee>
  <firstname>John</firstname>
  <lastname>Smith</lastname>
</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>
Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.