Elemento restriction XML Schema

Definizione e uso

L'elemento restriction definisce le restrizioni per simpleType, simpleContent o complexContent.

Informazioni sull'elemento

Frequenza di apparizione una volta
Padre elemento complexContent
Contenuto group、all、choice、sequence、attribute、attributeGroup、anyAttribute

Grammatica

<restriction
id=ID
base=QName
qualsiasi attributi
>
Contenuto per simpleType:
(annotation?,(simpleType?,(minExclusive|minInclusive| 
maxExclusive|maxInclusive|totalDigits|fractionDigits|
length|minLength|maxLength|enumeration|whiteSpace|pattern)*))
Contenuto per simpleContent:
(annotation?,(simpleType?,(minExclusive |minInclusive| 
maxExclusive|maxInclusive|totalDigits|fractionDigits|
(length|minLength|maxLength|enumeration|whiteSpace|pattern)*)?, 
((attribute|attributeGroup)*,anyAttribute?)
Contenuto per complexContent:
(annotation?,(group|all|choice|sequence)?,
((attribute|attributeGroup)*,anyAttribute?)
</restriction>

(?Simbolo dichiarato nell'elemento restriction, può apparire zero o una volta.)

属性 Descrizione
id Opzionale. Specifica l'ID unico dell'elemento.
base Obbligatorio. Specifica il nome degli elementi di tipo dati integrato, simpleType o complexType definiti nel presente schema (o in altri schema indicati da uno spazio dei nomi specificato).
qualsiasi attributi Opzionale. Specifica qualsiasi altra proprietà con命名空间 non schema.

Esempio

Esempio 1

Esempio di definizione di un elemento chiamato "age" con vincoli. Il valore di "age" non può essere inferiore a 0 o superiore a 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 un elemento chiamato "initials". L'elemento "initials" è di tipo semplice con vincoli. I valori accettati sono tre lettere maiuscole o minuscole da a a 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" è di tipo semplice con vincoli. Il valore deve essere composto da almeno 5 e massimo 8 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 complesso con vincoli. Il tipo complesso "Chinese_customer" deriva dal tipo complesso "customer" comune, con un valore fisso per l'elemento country "China":

<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="Chinese_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="China"/>
      </xs:sequence>
    </xs:restriction>
  </xs:complexContent>
</xs:complexType>