عنصر 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 این عنصر میتواند صفر یا یک بار ظاهر شود.)
ویژگیها | توضیحات |
---|---|
id | اختیاری. تعریف ID منحصر به فرد این عنصر. |
پایه | ضروری. تعریف نامهای دادههای داخلی، simpleType یا complexType در این شماتیک (یا شماتیک دیگری که با نام فضای مشخص شده اشاره دارد). |
ویژگیها | اختیاری. تعریف هر ویژگی دیگری که دارای فضای نام non-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" یک نوع ساده با محدودیتهاست. مقادیر قابل قبول سه حرف از الفبای انگلیسی بزرگ یا کوچک هستند:
<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>