عنصر restriction XML Schema

تعریف و استفاده

عنصر restriction تعریف محدودیت‌ها برای simpleType،simpleContent یا complexContent را تعریف می‌کند.

اطلاعات عنصر

تعداد ظهور بار
عنصر والد complexContent
محتوا group،all،choice،sequence،attribute،attributeGroup،anyAttribute

زبان

<restriction
id=ID
base=QName
ویژگی‌های دیگر
>
محتوای simpleType:
(annotation?,(simpleType?,(minExclusive|minInclusive| 
maxExclusive|maxInclusive|totalDigits|fractionDigits|
length|minLength|maxLength|enumeration|whiteSpace|pattern)*))
محتوای simpleContent:
(annotation?,(simpleType?,(minExclusive |minInclusive| 
maxExclusive|maxInclusive|totalDigits|fractionDigits|
(length|minLength|maxLength|enumeration|whiteSpace|pattern)*)?, 
((attribute|attributeGroup)*,anyAttribute?))
محتوای complexContent:
(annotation?,(group|all|choice|sequence)?,
((attribute|attributeGroup)*,anyAttribute?))
</restriction>

(؟ نمادهای اعلام شده در عنصر restriction این عنصر می‌تواند صفر یا یک بار ظاهر شود.)

ویژگی توضیح
شناسه اختیاری. مشخص می‌کند شناسه منحصر به فرد این عنصر.
اساس ضروری. مشخص می‌کند نام نوع داده‌های داخلی، simpleType یا complexType در این schema (یا schema‌های دیگر مشخص شده توسط نام‌ فضای معین شده).
ویژگی‌های دیگر اختیاری. مشخص می‌کند هرگونه ویژگی غیرشکلی.

مثال

مثال 1

این مثال یک عنصر به نام "age" با محدودیت‌ها تعریف می‌کند. مقدار 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" تعریف می‌کند. عنصر "initials" یک نوع ساده با محدودیت‌هاست. مقادیر قابل قبول سه حرف بزرگ یا کوچک از a تا 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>

مثال 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

این مثال نمایش یک تعریف نوع پیچیده با محدودیت‌ها را نشان می‌دهد. نوع پیچیده "Chinese_customer" از نوع پیچیده معمولی customer منشعب شده است و مقدار ثابت عناصر country او "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>