XML Schema restriction 元素
定义和用法
restriction 元素定义对 simpleType、simpleContent 或 complexContent 定义的约束。
元素信息
出现次数 | 一次 |
父元素 | complexContent |
内容 | group、all、choice、sequence、attribute、attributeGroup、anyAttribute |
语法
<restriction id=ID base=QName কোনও বৈশিষ্ট্য > 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>
(? 符号声明在 restriction 元素中该元素可出现零次或一次。)
属性 | বিবরণ |
---|---|
id | বাধ্যতাহীন। এই ইউনিটের অভিন্ন ID নির্দিষ্ট করা হয়。 |
base | বাধ্যতামূলক। schema-এর (অথবা নির্দিষ্ট নামক স্পেসের) মধ্যে নির্দিষ্ট বৃদ্ধিমান ধরন, simpleType বা complexType ইউনিটের নাম নির্দিষ্ট করা হয়。 |
কোনও বৈশিষ্ট্য | বাধ্যতাহীন। non-schema নামক সমস্ত অন্যান্য বৈশিষ্ট্য নির্দিষ্ট করা হয়。 |
প্রকৃত
উদাহরণ 1
এই উদাহরণটিতে "age" নামক ইউনিট নির্দিষ্ট করা হয়েছে। age-এর মান ০ থেকে ১০০-এর মধ্যে হবে না:
<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" ইউনিট একটি শৃঙ্খলাবদ্ধ সহজ ধরন। মানটি কমপক্ষে ৫ এবং সর্বোচ্চ ৮ বর্ণ হতে হবে:
<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>