Prvek omezení schématu XML
❮ Vyplňte odkaz na schéma XML
Definice a použití
Element omezení definuje omezení pro definici simpleType, simpleContent nebo complexContent.
Informace o prvku
- Nadřazené prvky: simpleType, simpleContent, complexContent
Syntax
<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>
(Znak ? deklaruje, že prvek se může uvnitř prvku omezení vyskytovat nula nebo jednou)
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 |
Příklad 1
Tento příklad definuje prvek zvaný „věk“ s omezením. Hodnota věku NEMŮŽE být nižší než 0 nebo vyšší než 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>
Příklad 2
Tento příklad také definuje prvek zvaný „iniciály“. Element „initials“ je jednoduchý typ s omezením. Jedinou přijatelnou hodnotou jsou TŘI VELKÁ NEBO VELKÁ písmena od a do 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>
Příklad 3
Tento příklad definuje prvek zvaný "heslo". Prvek "heslo" je jednoduchý typ s omezením. Hodnota musí mít minimálně pět znaků a maximálně osm znaků:
<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>
Příklad 4
Tento příklad ukazuje komplexní definici typu pomocí omezení. Komplexní typ „Norwegian_customer“ je odvozen od obecného typu komplexního zákazníka a jeho prvek země je pevně nastaven na „Norsko“:
<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>
❮ Vyplňte odkaz na schéma XML