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: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" ਏਜੰਟ ਸੀਮਾਬੱਧ ਸਰਲ ਵਰਗ ਹੈ। ਮੁੱਲ ਨੂੰ ਘੱਟੋ-ਘੱਟ 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>