XML Schema attribute ÔªËØ

¶¨ÒåºÍÓ÷¨

attribute ÔªËØ¶¨ÒåÒ»¸öÊôÐÔ¡£

ÔªËØÐÅÏ¢

³öÏÖ´ÎÊý ÔÚ schema ÔªËØÖж¨ÒåÒ»´Î¡£ ÔÚ¸´ÔÓÀàÐÍ»òÊôÐÔ×éÖÐÒýÓöà´Î¡£
¸¸ÔªËØ attributeGroup¡¢schema¡¢complexType¡¢restriction (simpleContent)¡¢extension (simpleContent)¡¢restriction (complexContent)¡¢extension (complexContent)
ÄÚÈÝ annotation¡¢simpleType

Óï·¨

<attribute
default=string
fixed=string
form=qualified|unqualified
id=ID
name=NCName
ref=QName
type=QName
use=optional|prohibited|required
any attributes
>

(annotation?,(simpleType?))

</attribute>

£¨? ·ûºÅÉùÃ÷¸ÃÔªËØ¿ÉÔÚ attribute ÔªËØÖгöÏÖÁã´Î»òÒ»´Î¡££©

ÊôÐÔ

default

¿ÉÑ¡¡£¹æ¶¨ÊôÐÔµÄĬÈÏÖµ¡£default ºÍ fixed ÊôÐÔ²»ÄÜͬʱ³öÏÖ¡£

fixed

¿ÉÑ¡¡£¹æ¶¨ÊôÐԵĹ̶¨Öµ¡£default ºÍ fixed ÊôÐÔ²»ÄÜͬʱ³öÏÖ¡£

form

¿ÉÑ¡¡£¹æ¶¨ÊôÐԵĸñʽ¡£Ä¬ÈÏÖµÊǰüº¬¸ÃÊôÐ﵀ schema ÔªËØµÄ attributeFormDefault ÊôÐÔµÄÖµ¡£¿ÉÒÔÉèÖÃΪÏÂÁÐÖµ£º

  • "qualified" - ָʾ±ØÐëͨ¹ýÃüÃû¿Õ¼äǰ׺ºÍ¸ÃÊôÐÔµÄÎÞðºÅÃû³Æ (NCName) À´ÏÞ¶¨´ËÊôÐÔ¡£
  • "unqualified" - ָʾ´ËÊôÐÔÎÞÐëÓÉÃüÃû¿Õ¼äǰ׺ÏÞ¶¨£¬ÇÒÎÞÐëÆ¥Åä´ËÊôÐÔµÄÎÞðºÅÃû³Æ (NCName)£¬¼´±¾µØÃû³Æ¡£

id

¿ÉÑ¡¡£¹æ¶¨¸ÃÔªËØµÄΨһµÄ ID¡£

name

¿ÉÑ¡¡£¹æ¶¨ÊôÐÔµÄÃû³Æ¡£name ºÍ ref ÊôÐÔ²»ÄÜͬʱ³öÏÖ¡£

ref

¿ÉÑ¡¡£¹æ¶¨¶ÔÖ¸¶¨µÄÊôÐÔµÄÒýÓá£name ºÍ ref ÊôÐÔ²»ÄÜͬʱ³öÏÖ¡£Èç¹û ref ³öÏÖ£¬Ôò simpleType ÔªËØ¡¢form ºÍ type ²»ÄܳöÏÖ¡£

type

¿ÉÑ¡¡£¹æ¶¨ÄÚ½¨µÄÊý¾ÝÀàÐÍ»ò¼òµ¥ÀàÐÍ¡£type ÊôÐÔÖ»ÄÜÔÚÄÚÈݲ»°üº¬ simpleType ÔªËØÊ±³öÏÖ¡£

use

¿ÉÑ¡¡£¹æ¶¨ÈçºÎʹÓøÃÊôÐÔ¡£¿ÉÉèÖÃÏÂÃæµÄÖµ£º

  • optional - ÊôÐÔÊÇ¿ÉÑ¡µÄ²¢ÇÒ¿ÉÒÔ¾ßÓÐÈκÎÖµ£¨Ä¬ÈÏ£©¡£
  • prohibited - ²»ÄÜʹÓÃÊôÐÔ¡£
  • required - ÊôÐԵıØÐèµÄ¡£

any attributes

¿ÉÑ¡¡£¹æ¶¨´øÓÐ non-schema ÃüÃû¿Õ¼äµÄÈÎºÎÆäËûÊôÐÔ¡£

ʵÀý

Àý×Ó 1

<xs:attribute name="code">

<xs:simpleType>
  <xs:restriction base="xs:string">
    <xs:pattern value="[A-Z][A-Z]"/>
  </xs:restriction>
</xs:simpleType>

</xs:attribute>

ÉÏÃæµÄÀý×Óָʾ "code" ÊôÐÔÓÐÒ»¸öÏÞ¶¨¡£Î¨Ò»¿É½ÓÊܵÄÖµÊÇ´óд×Öĸ A µ½ Z ÖеÄÁ½¸ö×Öĸ¡£

Àý×Ó 2

ÈçÐèʹÓÃÔÚ¸´ÔÓÀàÐÍÖÐÒ»¸öÒÑÓеÄÊôÐÔ¶¨ÒåÀ´ÉùÃ÷Ò»¸öÊôÐÔ£¬ÇëʹÓà ref ÊôÐÔ£º

<xs:attribute name="code">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:pattern value="[A-Z][A-Z]"/>
    </xs:restriction>
  </xs:simpleType>
</xs:attribute>

<xs:complexType name="someComplexType">
  <xs:attribute ref="code"/>
</xs:complexType>

Àý×Ó 3

ÊôÐԼȿÉÒÔÓµÓÐĬÈÏÖµ£¬Ò²¿ÉÒÔÓµÓÐÖ¸¶¨µÄ¹Ì¶¨Öµ¡£ÔÚûÓÐÆäËûµÄÖµ±»Ö¸¶¨Ê±£¬»á×Ô¶¯ÏòÊôÐÔ¸³ÓèĬÈÏÖµ¡£ÔÚÏÂÃæµÄÀý×ÓÖУ¬Ä¬ÈÏÖµÊÇ "EN"£º

<xs:attribute name="lang" type="xs:string" default="EN"/>

ÔÚûÓÐÆäËûµÄÖµ±»Ö¸¶¨Ê±£¬»á×Ô¶¯ÏòÊôÐÔ¸³Óè¹Ì¶¨Öµ¡£µ«ÊÇÓëĬÈÏÖµ²»Í¬£¬Èç¹ûÄúΪÊôÐԹ涨Á˹̶¨ÖµÒÔÍâµÄÆäËûÖµ£¬Îĵµ»áÑé֤ΪÎÞЧ¡£ÔÚÏÂÃæµÄÀý×ÓÖУ¬¹Ì¶¨ÖµÊÇ "EN"£º

<xs:attribute name="lang" type="xs:string" fixed="EN"/>

Àý×Ó 4

ËùÓÐÊôÐÔĬÈ϶¼ÊÇ¿ÉÑ¡µÄ¡£ÈçÐèÃ÷È·µØ¹æ¶¨ÊôÐÔΪ¿ÉÑ¡£¬ÇëʹÓà "use" ÊôÐÔ£º

<xs:attribute name="lang" type="xs:string" use="optional"/>

ʹÊôÐÔ³ÉΪ±ØÐèµÄÊôÐÔ£º

<xs:attribute name="lang" type="xs:string" use="required"/>
VUE