Elemento di restrizione dello schema XML
❮ Riferimento completo allo schema XML
Definizione e utilizzo
L'elemento di restrizione definisce le restrizioni su una definizione simpleType, simpleContent o complexContent.
Informazioni sull'elemento
- Elementi principali: simpleType, simpleContent, complexContent
Sintassi
<restriction
id=ID
base=QName
any attributes
>
Content for simpleType:
(annotation?,(simpleType?,(minExclusive|minInclusive|
maxExclusive|maxInclusive|totalDigits|fractionDigits|
length|minLength|maxLength|enumeration|whiteSpace|pattern)*))
Content for simpleContent:
(annotation?,(simpleType?,(minExclusive |minInclusive|
maxExclusive|maxInclusive|totalDigits|fractionDigits|
length|minLength|maxLength|enumeration|whiteSpace|pattern)*)?,
((attribute|attributeGroup)*,anyAttribute?))
Content for complexContent:
(annotation?,(group|all|choice|sequence)?,
((attribute|attributeGroup)*,anyAttribute?))
</restriction>
(Il segno ? dichiara che l'elemento può verificarsi zero o una volta all'interno dell'elemento di restrizione)
Attribute | Description |
---|---|
id | Optional. Specifies a unique ID for the element |
base |
Required. Specifies the name of a built-in data type, simpleType element, or complexType element defined in this schema or another schema |
any attributes | Optional. Specifies any other attributes with non-schema namespace |
Esempio 1
Questo esempio definisce un elemento chiamato "età" con una restrizione. Il valore dell'età NON può essere inferiore a 0 o maggiore di 100:
<xs:element name="age">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="100"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Esempio 2
Questo esempio definisce anche un elemento chiamato "initials". L'elemento "initials" è un tipo semplice con una restrizione. L'unico valore accettabile è TRE delle lettere MAIUSCOLE O MAIUSCOLE dalla a alla z:
<xs:element name="initials">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z][a-zA-Z][a-zA-Z]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Esempio 3
Questo esempio definisce un elemento chiamato "password". L'elemento "password" è un tipo semplice con una restrizione. Il valore deve essere minimo cinque caratteri e massimo otto caratteri:
<xs:element name="password">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="5"/>
<xs:maxLength value="8"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Esempio 4
Questo esempio mostra una definizione di tipo complessa che utilizza la restrizione. Il tipo complesso "Norwegian_customer" deriva da un tipo complesso cliente generale e il relativo elemento paese è fissato a "Norvegia":
<xs:complexType name="customer">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Norwegian_customer">
<xs:complexContent>
<xs:restriction base="customer">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
<xs:element name="country" type="xs:string" fixed="Norway"/>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
❮ Riferimento completo allo schema XML