XML-элемент схемы ограничения
Определение и использование
Определение элемента ограничение simpleType, simpleContent или complexContent определенные ограничения.
Элемент информации
- Родительский элемент: simpleType, simpleContent, complexContent
грамматика
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>
(? Знак заявляет, что ограничение элемент элемента может произойти ноль или один раз.)
属性 | 描述 |
---|---|
id | 可选。规定该元素的唯一的 ID。 |
base | 必需。规定在该 schema(或由指定的命名空间指示的其他 schema)中定义的内建数据类型、simpleType 或 complexType 元素的名称。 |
any attributes | 可选。规定带有 non-schema 命名空间的任何其他属性。 |
Пример 1
Следующий пример определяет элемент с ограничением и называется "возраст". Значение возраста не может быть меньше, чем 0 или больше, чем 100:
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="100"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Пример 2
Этот пример определяет элемент "инициалами" по имени. Элемент "Инициалы" является простой тип с ограничением. Допустимые значения: от А до Я трех заглавных и строчных букв:
<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>
Пример 3
Этот пример определяет элемент с именем "пароль". элемент "Пароль" является простой тип с ограничением. Значение должно быть не менее пяти символов и не более восьми символов:
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="5"/>
<xs:maxLength value="8"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Пример 4
Этот пример показывает, сложный тип, определенный с использованием ограничений. Комплекс типа "Chinese_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 - схемы Справочник