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 को निर्दिष्ट करता है。
आधार अनिवार्य। इस schema (या निर्दिष्ट नामस्पाद द्वारा इंगित किए गए अन्य schema) में परिभाषित बीजकरण वाले डेटा प्रकार, 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>