XML Schema all 元素
完整 XML Schema 參考手冊
定義和用法
元素規(guī)定子元素能夠以任意順序出現(xiàn),每個子元素可出現(xiàn)零次或一次。
元素信息
- 父元素: group, complexType, restriction (both simpleContent and complexContent), extension (both simpleContent and complexContent)
語法
<all
id=ID
maxOccurs=1
minOccurs=0|1
any attributes
>
(annotation?,element*)
</all>
(? 符號聲明該元素可出現(xiàn)零次或一次,而 * 符號聲明該元素可在所有元素中出現(xiàn)零次或多次。)
屬性 | 描述 |
id | 可選。該元素的唯一標(biāo)識符。 |
maxOccurs | 可選。元素可出現(xiàn)的最大次數(shù)。 該值必須是 1。 |
minOccurs | 可選。元素可出現(xiàn)的最小次數(shù)。 該值可以是整數(shù) 0 或 1。若要指定該元素是可選的,請將該屬性設(shè)置為 0。 默認(rèn)值為 1。 |
any attributes | 可選。規(guī)定帶有 non-schema 命名空間的任何其他屬性。 |
實例 1
<xs:element name="person">
??<xs:complexType>
????<xs:all>
??????<xs:element name="firstname" type="xs:string"/>
??????<xs:element name="lastname" type="xs:string"/>
????</xs:all>
??</xs:complexType>
</xs:element>
上面的例子指示 "firstname" 和 "lastname" 元素能夠以任何順序出現(xiàn),兩個元素都必須且只能出現(xiàn)一次!
實例 2
<xs:element name="person">
??<xs:complexType>
????<xs:all minOccurs="0">
??????<xs:element name="firstname" type="xs:string"/>
??????<xs:element name="lastname" type="xs:string"/>
????</xs:all>
??</xs:complexType>
</xs:element>
上面的例子指示 "firstname" 和 "lastname" 元素能夠以任何順序出現(xiàn),每個元素都能出現(xiàn)零次或一次!
完整 XML Schema 參考手冊
更多建議: