Element XML Schema restriction
Definicja i zastosowanie
Element restriction definiuje ograniczenia dla simpleType, simpleContent lub complexContent.
Informacje o elemencie
Liczba wystąpień | Raz |
Rodzic elementu | complexContent |
Zawartość | group、all、choice、sequence、attribute、attributeGroup、anyAttribute |
Gramatyka
<restriction id=ID base=QName any attributes > Zawartość dla simpleType: (annotation?,(simpleType?,(minExclusive|minInclusive| maxExclusive|maxInclusive|totalDigits|fractionDigits| length|minLength|maxLength|enumeration|whiteSpace|pattern)*)) Zawartość dla simpleContent: (annotation?,(simpleType?,(minExclusive |minInclusive| maxExclusive|maxInclusive|totalDigits|fractionDigits| (length|minLength|maxLength|enumeration|whiteSpace|pattern)*)?, ((attribute|attributeGroup)*,anyAttribute?) Zawartość dla complexContent: (annotation?,(group|all|choice|sequence)?, ((attribute|attributeGroup)*,anyAttribute?) </restriction>
(? Symbol deklaracji w elemencie restriction oznacza, że ten element może występować zero lub jeden raz.)
Atrybuty | Opis |
---|---|
id | Dostępne. Określa unikalny ID tego elementu. |
base | Wymagane. Określa nazwy wbudowanych typów danych, simpleType lub elementów complexType zdefiniowanych w tym schema (lub innym schema wskazanym przez przestrzeń nazw). |
any attributes | Dostępne. Określa inne atrybuty z przestrzeni nazw non-schema. |
Przykład
Przykład 1
Poniższy przykład definiuje element o nazwie "age" z ograniczeniami. Wartość "age" nie może być mniejsza niż 0 ani większa niż 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>
Przykład 2
W tym przykładzie zdefiniowano element o nazwie "initials". Element "initials" jest typem prostym z ograniczeniami. Akceptowalne wartości to trzy duże lub małe litery z zakresu 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>
Przykład 3
W tym przykładzie zdefiniowano element o nazwie "password". Element "password" jest typem prostym z ograniczeniami. Wartość musi składać się z co najmniej 5 znaków i co najwyżej 8 znaków:
<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>
Przykład 4
W tym przykładzie pokazano złożony typ definicji używający ograniczeń. Złożony typ "Chinese_customer" jest pochodną typy "customer", a wartość stała elementu "country" wynosi "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>