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 元素中该元素可出现零次或一次。)

属性 వివరణ
ఐడి ఆప్షనల్. ఈ అంశం యొక్క ప్రత్యేక ఐడి ని నిర్వచించు.
బేస్ అత్యవసరం. ఈ స్కీమా (లేదా సూచించిన నామకం ద్వారా ఇతర స్కీమా) లో నిర్వచించబడిన అంతర్గత డేటా రకాలు, simpleType లేదా complexType అంశాల పేరును నిర్వచించు.
ఏదైనా అంశాలు ఆప్షనల్. నాణ్యమైన స్కీమా నామకం కలిగిన ఏదైనా ఇతర అంశాలను నిర్వచించు.

ఉదాహరణ

ఉదాహరణ 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: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: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:simpleType>
</xs:element>

ఉదాహరణ 4

ఈ ఉదాహరణ ఒక బాధ్యతా కలిగిన క్లిష్ట రకం నిర్వచనాన్ని ప్రదర్శిస్తుంది. క్లిష్ట రకం "Chinese_customer" సాధారణ customer క్లిష్ట రకం నుండి ఉద్భవించింది, దాని country అంశం నిర్ధిష్ట విలువ "China":

<xs:complexType name="customer">
  
    
    
    <xs:element name="country" type="xs:string"/>
  

<xs:complexType name="Chinese_customer">
  <xs:complexContent>