XML Schema attribute element

Definition and Usage

The attribute element defines an attribute.

Element Information

Occurrence Defined once in the schema element. Referenced multiple times in complex types or attribute groups.
Parent Element attributeGroup, schema, complexType, restriction (simpleContent), extension (simpleContent), restriction (complexContent), extension (complexContent)
Content annotation, simpleType

Syntax

<attribute
default=string
fixed=string
form=qualified|unqualified
id=ID
name=NCName
ref=QName
type=QName
use=optional|prohibited|required
alle eigenschappen
>
(annotation?,(simpleType?))
</attribute>

(The '?' symbol indicates that the element can appear zero or one times in the attribute element.)

Attribute

default

Optional. Specifies the default value of the attribute. The default and fixed attributes cannot appear at the same time.

fixed

Optional. Specifies the fixed value of the attribute. The default and fixed attributes cannot appear at the same time.

form

Optional. Specifies the format of the attribute. The default value is the value of the attributeFormDefault attribute of the schema element containing the attribute. It can be set to the following values:

  • "qualified" - Indicates that this attribute must be qualified with a namespace prefix and the non-colon name (NCName) of the attribute.
  • "unqualified" - Geef aan dat deze eigenschap geen namespace-prefix hoeft te hebben en geen match hoeft te maken met de ongekwalificeerde naam (NCName) van deze eigenschap, dat wil zeggen de lokale naam.

id

Optioneel. Specificeer het unieke ID van dit element.

name

Optioneel. Specificeer de naam van de eigenschap. De name- en ref-eigenschappen mogen niet tegelijkertijd optreden.

ref

Optioneel. Specificeer een verwijzing naar de gespecificeerde eigenschap. De name- en ref-eigenschappen mogen niet tegelijkertijd optreden. Als ref optreedt, mogen de simpleType-element, form en type niet optreden.

type

Optioneel. Specificeer een ingebouwde datatype of eenvoudig type. De type-eigenschap mag alleen optreden wanneer de inhoud geen simpleType-element bevat.

gebruik

Optioneel. Specificeer hoe de eigenschap moet worden gebruikt. De volgende waarden kunnen worden ingesteld:

  • optioneel - Eigenschap is optioneel en kan elke waarde hebben (standaard).
  • verboden - Eigenschap kan niet worden gebruikt.
  • verplicht - Eigenschap is vereist.

alle eigenschappen

Optioneel. Specificeer andere eigenschappen met een non-schema naamruimte.

Voorbeeld

Voorbeeld 1

<xs:attribute name="code">
<xs:simpleType>
  <xs:restriction base="xs:string">
    <xs:pattern value="[A-Z][A-Z]"/>
  </xs:restriction>
</xs:simpleType>
</xs:attribute>

Deze voorbeeld geeft aan dat de "code"-eigenschap een beperking heeft. De enige aanvaardbare waarden zijn twee letters uit het alfabet A tot Z.

Voorbeeld 2

Om een bestaande eigenschapsdefinitie in een complex type te gebruiken om een eigenschap te declareren, gebruik dan de ref-eigenschap:

<xs:attribute name="code">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:pattern value="[A-Z][A-Z]"/>
    </xs:restriction>
  </xs:simpleType>
</xs:attribute>
<xs:complexType name="someComplexType">
  <xs:attribute ref="code"/>
</xs:complexType>

Voorbeeld 3

Een eigenschap kan zowel een standaardwaarde als een gespecificeerde vaste waarde hebben. Als geen andere waarde wordt gespecificeerd, wordt de standaardwaarde automatisch aan de eigenschap toegewezen. In het volgende voorbeeld is de standaardwaarde "EN":

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

Als geen andere waarde wordt gespecificeerd, wordt de eigenschap automatisch een vaste waarde toegewezen. Maar in tegenstelling tot de standaardwaarde, wordt een andere waarde dan de vaste waarde die aan de eigenschap is toegewezen, geverifieerd als ongeldig. In het volgende voorbeeld is de vaste waarde "EN":

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

Voorbeeld 4

Alle eigenschappen zijn standaard optioneel. Gebruik de "use" eigenschap om een eigenschap expliciet optioneel te specificeren:

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

Maak een eigenschap vereist:

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