عنصر restriction في XML Schema

التعريف والاستخدام

عنصر restriction يحدد القيود على simpleType أو simpleContent أو complexContent المحددة.

معلومات العنصر

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

النحو

<restriction
id=ID
base=QName
any attributes
>
محتوى برای 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 يمكن أن يظهر صفر مرات أو مرة واحدة.)

موصوفات 描述
id 可选。规定该元素的唯一的 ID。
base 必需。规定在该 schema(或由指定的命名空间指示的其他 schema)中定义的内建数据类型、simpleType 或 complexType 元素的名称。
any attributes اختیاری۔ باقی کیں نامیں کسی غیر شکلا تعیناتی نمائش نامیں کا تعریف کرتا ہے۔

مثال

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