XML 스키마 제한 요소
❮ 완전한 XML 스키마 참조
정의 및 사용
제한 요소는 simpleType, simpleContent 또는 complexContent 정의에 대한 제한을 정의합니다.
요소 정보
- 상위 요소: simpleType, simpleContent, complexContent
통사론
<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>
(? 기호는 요소가 제한 요소 내에서 0 또는 1회 발생할 수 있음을 선언합니다.)
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 |
실시예 1
이 예에서는 제한이 있는 "연령"이라는 요소를 정의합니다. age 값은 0보다 작거나 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>
실시예 2
이 예에서는 "이니셜"이라는 요소도 정의합니다. "initials" 요소는 제한이 있는 단순 유형입니다. 허용되는 유일한 값은 a에서 z까지의 소문자 또는 대문자 중 3개입니다.
<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>
실시예 3
이 예는 "password"라는 요소를 정의합니다. "password" 요소는 제한이 있는 단순 유형입니다. 값은 최소 5자에서 최대 8자여야 합니다.
<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>
실시예 4
이 예는 제한을 사용하는 복합 유형 정의를 보여줍니다. 복합 유형 "Norwegian_customer"는 일반 고객 복합 유형에서 파생되며 해당 국가 요소는 "노르웨이"로 고정됩니다.
<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 스키마 참조