Latest web development tutorials

XML Schema elementem ograniczenia

XML Schema Reference Kompletna XML Schema Reference

Definicja i Wykorzystanie

Definicja elementem ograniczenia simpleType, simpleContent lub complexContent zdefiniowane ograniczenia.

Element informacji

  • Parent Element: simpleType, simpleContent, complexContent

gramatyka

<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 element ograniczenie elementu może wystąpić zero lub jeden raz).

属性 描述
id 可选。规定该元素的唯一的 ID。
base 必需。规定在该 schema(或由指定的命名空间指示的其他 schema)中定义的内建数据类型、simpleType 或 complexType 元素的名称。
any attributes 可选。规定带有 non-schema 命名空间的任何其他属性。

Przykład 1

Poniższy przykład definiuje element z przymusu i nazywa się "wiek". Wartość życia nie może być mniejsza niż 0 lub większy 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

Ten przykład definiuje "inicjały" element o nazwie. "Inicjały" elementem jest prosty typ z ograniczeniem. Dopuszczalne wartości: od A do Z trzech wielkich lub małych liter:

<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

Ten przykład definiuje nazwie "hasło" element. "Hasło" elementem jest prosty typ z ograniczeniem. Wartość musi być co najmniej pięciu i nie więcej niż ośmiu 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

Przykład ten pokazuje typ złożony zdefiniowanego za pomocą wiązań. Kompleks typu "Chinese_customer" od zwykłej typów złożonych pochodzących od klientów, wartości jego stałym elementem jest krajem "Chiny":

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


XML Schema Reference Kompletna XML Schema Reference