Gli ultimi tutorial di sviluppo web
 

XML Schema di restrizione Element


<Schema di riferimento XML completo

Definizione e utilizzo

L'elemento di restrizione definisce restrizioni su una definizione simpleType, simpleContent o complexContent.

Informazioni elemento

  • Parent elements: 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>

(L'? Segno dichiara che l'elemento può verificarsi zero o una volta dentro l'elemento di restrizione)

Attributo Descrizione
id Facoltativo. Specifica un ID univoco per l'elemento
base

Richiesto. Specifica il nome di un tipo incorporato nei dati, elemento simpleType, o elemento complexType definito in questo schema o un altro schema

any attributes Facoltativo. Specifica qualsiasi altro attributo con i non-schema namespace

esempio 1

Questo esempio definisce un elemento chiamato "age" con una limitazione. Il valore di 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" . Il "initials" elemento è un tipo semplice con una limitazione. L'unico valore accettabile è tre dei minuscola o maiuscola, lettere 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" . La "password" elemento è un tipo semplice con una restrizione. Il valore deve essere almeno 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 complesso con restrizione. Il tipo complesso "Norwegian_customer" deriva da un generale cliente tipo complesso e il suo elemento paese è fissa "Norway" :

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

<Schema di riferimento XML completo