XML Schema restriction ÔªËØ
¶¨ÒåºÍÓ÷¨
restriction ÔªËØ¶¨Òå¶Ô simpleType¡¢simpleContent »ò complexContent ¶¨ÒåµÄÔ¼Êø¡£
ÔªËØÐÅÏ¢
³öÏÖ´ÎÊý | Ò»´Î |
¸¸ÔªËØ | complexContent |
ÄÚÈÝ | group¡¢all¡¢choice¡¢sequence¡¢attribute¡¢attributeGroup¡¢anyAttribute |
Óï·¨
<restriction id=ID base=QName any attributes > 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£¨»òÓÉÖ¸¶¨µÄÃüÃû¿Õ¼äָʾµÄÆäËû schema£©Öж¨ÒåµÄÄÚ½¨Êý¾ÝÀàÐÍ¡¢simpleType »ò complexType ÔªËØµÄÃû³Æ¡£ |
any attributes | ¿ÉÑ¡¡£¹æ¶¨´øÓÐ 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" ÔªËØÊÇ´øÓÐÔ¼ÊøµÄ¼òµ¥ÀàÐÍ¡£¿É½ÓÊܵÄÖµÊÇÈý¸ö´Ó 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>