XML Schema restriction عنصر

تعریف اور استعمال

restriction عنصر داخلی نوعیت،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 عناصر کا نام دیتا ہے۔
کوئی بھی دیگر اتریت اختیاری۔non-schema نام فضا کا کوئی بھی دیگر اتریت کا تعین کرتا ہے۔

实例

例子 1

下面的例子定义了一个带有约束且名为 "age" 的元素。age 的值不能小于 0 或大于 100:


  
    
      
      
    </xs:restriction>
  

例子 2

本例定义了一个名为 "initials" 的元素。"initials" 元素是带有约束的简单类型。可接受的值是三个从 a 到 z 的大写或小写字母:


  
    
      
    </xs:restriction>
  

例子 3

本例定义了一个名为 "password" 元素。"password" 元素是带有约束的简单类型。值必须为最少 5 个字符且最多 8 个字符:


  
    
      
      
    </xs:restriction>
  

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