XML Şeması kısıtlama Öğesi
❮ Eksiksiz XML Şeması Referansı
Tanım ve Kullanım
Kısıtlama öğesi, bir simpleType, simpleContent veya ComplexContent tanımındaki kısıtlamaları tanımlar.
Eleman Bilgileri
- Ana öğeler: simpleType, simpleContent, ComplexContent
Sözdizimi
<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>
(? işareti, öğenin kısıtlama öğesi içinde sıfır veya bir kez oluşabileceğini bildirir)
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 |
örnek 1
Bu örnek, bir kısıtlama ile "yaş" adlı bir öğeyi tanımlar. Yaş değeri 0'dan küçük veya 100'den büyük olamaz:
<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>
Örnek 2
Bu örnek aynı zamanda "baş harfler" adlı bir öğeyi de tanımlar. "Baş harfler" öğesi, kısıtlaması olan basit bir türdür. Kabul edilebilir tek değer, a'dan z'ye kadar olan ÜÇ HARF VEYA BÜYÜK HARF'tir:
<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>
Örnek 3
Bu örnek, "parola" adlı bir öğeyi tanımlar. "Parola" öğesi, kısıtlaması olan basit bir türdür. Değer minimum beş karakter ve maksimum sekiz karakter olmalıdır:
<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>
Örnek 4
Bu örnek, kısıtlama kullanan karmaşık bir tür tanımını gösterir. "Norwegian_customer" karmaşık türü, genel bir müşteri karmaşık türünden türetilmiştir ve ülke öğesi "Norveç" olarak sabitlenmiştir:
<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>
❮ Eksiksiz XML Şeması Referansı