Latest web development tutorials

XML Schema all 元素

XML Schema 參考手冊 完整XML Schema參考手冊

定義和用法

元素規定子元素能夠以任意順序出現,每個子元素可出現零次或一次。

元素信息

  • 父元素: 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>

(? 符號聲明該元素可出現零次或一次,而* 符號聲明該元素可在所有元素中出現零次或多次。)

屬性 描述
id 可選。 該元素的唯一標識符。
maxOccurs 可選。 元素可出現的最大次數。 該值必須是1。
minOccurs 可選。 元素可出現的最小次數。 該值可以是整數0 或1。 若要指定該元素是可選的,請將該屬性設置為0。 默認值為1。
any attributes 可選。 規定帶有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" 元素能夠以任何順序出現,兩個元素都必須且只能出現一次!

實例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" 元素能夠以任何順序出現,每個元素都能出現零次或一次!


XML Schema 參考手冊 完整XML Schema參考手冊