عنصر تقييد مخطط 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>
(تعلن العلامة أن العنصر يمكن أن يحدث صفرًا أو مرة واحدة داخل عنصر التقييد)
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
يعرّف هذا المثال عنصرًا يسمى "عمر" بقيد. لا يمكن أن تكون قيمة العمر أقل من 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
يعرّف هذا المثال أيضًا عنصرًا يسمى "الأحرف الأولى". عنصر "الأحرف الأولى" هو نوع بسيط له قيود. القيمة الوحيدة المقبولة هي ثلاثة أحرف من الأحرف الصغيرة أو الكبيرة من 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
يعرّف هذا المثال عنصرًا يسمى "كلمة المرور". عنصر "كلمة المرور" هو نوع بسيط مع تقييد. يجب ألا تقل القيمة عن خمسة أحرف ولا تزيد عن ثمانية أحرف:
<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 الكامل