15.2.7. XSD attribute

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

All properties are declared as simple types.

What is an attribute?

Simple elements cannot have attributes. If an element has an attribute, it is treated as a compound type. But the property itself is always declared as a simple type.

How do I declare properties?

The syntax for defining attributes is

<xs:attribute name="xxx" type="yyy"/>

Here, xxx refers to the name of the attribute, and yyy specifies the data type of the attribute. XML Schema has many built-in data types.

The most common types are:

  • Xs:string

  • Xs:decimal

  • Xs:integer

  • Xs:boolean

  • Xs:date

  • Xs:time

Example

This is the XML element with attributes:

<lastname lang="EN">Smith</lastname>

This is the corresponding attribute definition:

<xs:attribute name="lang" type="xs:string"/>

Default value and fixed value of the attribute

Property can have a specified default value or fixed value.

When no other value is specified, the default value is automatically assigned to the element.

In the following example, the default value is “EN”:

<xs:attribute name="lang" type="xs:string" default="EN"/>

Fixed values are also automatically assigned to elements, and you cannot specify additional values.

In the following example, the fixed value is “EN”:

<xs:attribute name="lang" type="xs:string" fixed="EN"/>

Optional and required properties

By default, properties are optional. To specify the attribute as required, use the “use” attribute:

<xs:attribute name="lang" type="xs:string" use="required"/>

Limitation of content

When an XML element or attribute has a defined data type, a qualification is added to the content of the element or attribute.

If the XML element is of type “xs:date” and contains a string similar to “Hello World”, the element will not be validated.

With XML schema, you can also add your own qualifications to your XML elements and attributes. These qualifiers are called facet. You’ll learn more about facet in the next section.

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.