XML Skema beperking Element
❮ Voltooi XML-skemaverwysing
Definisie en gebruik
Die beperkingselement definieer beperkings op 'n simpleType, simpleContent of complexContent definisie.
Elementinligting
- Ouerelemente : simpleType, simpleContent, complexContent
Sintaksis
<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>
(Die ? teken verklaar dat die element nul of een keer binne die beperkingselement kan voorkom)
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 |
Voorbeeld 1
Hierdie voorbeeld definieer 'n element genaamd "ouderdom" met 'n beperking. Die waarde van ouderdom kan NIE laer as 0 of groter as 100 wees nie:
<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>
Voorbeeld 2
Hierdie voorbeeld definieer ook 'n element genaamd "voorletters". Die "voorletters" element is 'n eenvoudige tipe met 'n beperking. Die enigste aanvaarbare waarde is DRIE van die KLEIN- OF HOOFLETTERS van a tot 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>
Voorbeeld 3
Hierdie voorbeeld definieer 'n element genaamd "wagwoord". Die "wagwoord"-element is 'n eenvoudige tipe met 'n beperking. Die waarde moet minimum vyf karakters en maksimum agt karakters wees:
<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>
Voorbeeld 4
Hierdie voorbeeld toon 'n komplekse tipe definisie deur gebruik te maak van beperking. Die komplekse tipe "Norwegian_customer" is afgelei van 'n algemene kliënt komplekse tipe en sy landelement is vasgestel op "Noorweë":
<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>
❮ Voltooi XML-skemaverwysing