15.2.7. XSD attribute

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

Page Views: 10 views

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

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.

《地理信息系统原理、技术与方法》  97

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