| Content model | Mixed | Complex | Simple | Empty |
| Child elements | Yes | Yes | No | No |
| Child text | Yes | No | Yes | No |
注:由于Complex Type用于定義內部節點(diǎn),Content Model用于表示該節點(diǎn)所包含子節點(diǎn)的類(lèi)型。
Empty Content Complex Type:表示節點(diǎn)不包含任何文本和子節點(diǎn)的Complex Type類(lèi)型。
Simple Content Complex Type:表示節點(diǎn)只包含文本的Complex Type類(lèi)型。
Complex Content Complex Type:表示節點(diǎn)只包含子節點(diǎn)的Complex Type類(lèi)型。
Mixed Content Complex Type:表示節點(diǎn)的子節點(diǎn)當中既包含文本又能包含子節點(diǎn)的Complex Type類(lèi)型。
c) 定義Complex Type的語(yǔ)法:
<complexType
abstract = boolean : false
block = (#
all | List of (extension | restriction))
final = (#all | List of (extension | restriction))
id = ID
mixed = boolean : false
name = NCName
>
Content: (annotation?, (simpleContent | complexContent | ((group |
all |
choice |
sequence)?, ((attribute | attributeGroup)*, anyAttribute?))))
</complexType>
2. Simple Content Complex Type
a) 說(shuō)明:我們不能直接定義Simple Content Complex Type類(lèi)型,而必須通過(guò)對已有的Simple Type或者Simple Content進(jìn)行擴展或約束得到。
b) Simple Content的擴展(extension)
i. 說(shuō)明:對基類(lèi)型進(jìn)行擴展,定義額外的屬性。
ii. 語(yǔ)法:
<extension
base = QName
id = ID
>
Content: (annotation?, ((attribute | attributeGroup)*, anyAttribute?))
</extension>
iii. 例子:
Schema:
<xs:element name="title">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="note" type="xs:token"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
XML:
<title note="…">…</title>
c) Simple Content的約束(restriction)
i. 說(shuō)明:可以對基類(lèi)型中,已定義的內容和屬性進(jìn)行約束。通過(guò)修改屬性的use屬性,可以禁止該屬性的出現。約束后的類(lèi)型是基類(lèi)型的子集。
ii. 語(yǔ)法:
<restriction
base = QName
id = ID
>
Content: (annotation?, (simpleType?, (minExclusive | minInclusive | maxExclusive
| maxInclusive | totalDigits | fractionDigits | length | minLength | maxLength |
enumeration | whiteSpace | pattern)*)?, ((attribute | attributeGroup)*,
anyAttribute?))
iii. 例子:
Schema:
<xs:element name="title">
<xs:complexType>
<xs:simpleContent>
<xs:restriction base="xs:string">
<xs:maxLength value="5"/>
</xs:restriction>
</xs:simpleContent>
</xs:complexType>
</xs:element>
XML:
<title>Hello</title>
d) 兩種方法的比較:
擴展的方式只能增加新的屬性,而不能對基類(lèi)型當中的文本和屬性進(jìn)行任何的約束和修改。相比之下,約束的方式顯得更加靈活,她能夠增加對基類(lèi)型中的文本和屬性的約束。
3. Complex Content Complex Type
a) 說(shuō)明:我們能夠通過(guò)Compositor和Partical的方式,直接定義Complex Content Complex Type類(lèi)型,也能夠通過(guò)擴展和約束的方式,對已有的Complex Content Complex Type類(lèi)型進(jìn)行擴展。
b) 通過(guò)Compositor和Partical定義Complex Content Complex Type
Compositor和Partical用于定義子節點(diǎn)及其之間的關(guān)系。其中Compositor用于說(shuō)明子節點(diǎn)之間的出現順序,Partical用于說(shuō)明都包含了哪些子節點(diǎn)。Schema定義的Compositor包括:sequence,choice,all;Partical包括:element,sequence,choice,any和group。
i. sequence
1. 說(shuō)明:sequence中的Partical必須按順序出現。
2. 語(yǔ)法:
<sequence
id = ID
maxOccurs = (nonNegativeInteger | unbounded) : 1
minOccurs = nonNegativeInteger : 1
>
Content: (annotation?, (element | group | choice | sequence | any)*)
</sequence>
3. 例子:
Schema:
<xs:element name="author">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="born" type="xs:string"/>
</xs:sequence>
<xs:attribute name="id" type="xs:string"/>
</xs:complexType>
</xs:element>
XML:
<author id="…">
<name>…</name>
<born>…</born>
</author>
ii. choice
1. 說(shuō)明:choice中的Partical只能出現其中的一個(gè)。
2. 語(yǔ)法:
<choice
id = ID
maxOccurs = (nonNegativeInteger | unbounded) : 1
minOccurs = nonNegativeInteger : 1
>
Content: (annotation?, (element | group | choice | sequence | any)*)
</choice>
3. 例子:
Schema:
<xs:element name="author">
<xs:complexType>
<xs:choice>
<xs:element name="name" type="xs:string"/>
<xs:element name="born" type="xs:string"/>
</xs:choice>
<xs:attribute name="id" type="xs:string"/>
</xs:complexType>
</xs:element>
XML:
<author id="…">
<name>…</name>
</author>
iii. all
1. 說(shuō)明:all中的Partical可以按任何順序組合出現,但all中的Partical的maxOccurs屬性只能小于或等于1。
2. 語(yǔ)法:
<all
id = ID
maxOccurs = 1 : 1
minOccurs = (0 | 1) : 1
>
Content: (annotation?, element*)
</all>
3. 例子:
Schema:
<xs:element name="author">
<xs:complexType>
<xs:all>
<xs:element name="name" maxOccurs="1" type="xs:string"/>
<xs:element name="born" maxOccurs="1" type="xs:string"/>
</xs:all>
<xs:attribute name="id" type="xs:string"/>
</xs:complexType>
</xs:element>
XML:
<author id="…">
<born>…</born>
<name>…</name>
</author>
c) Complex Content的擴展(extention)
i. 說(shuō)明:對基類(lèi)型進(jìn)行擴展,定義額外的元素和屬性。
ii. 語(yǔ)法:
<extension
base = QName
id = ID
>
Content: (annotation?, ((group | all | choice | sequence)?, ((attribute |
attributeGroup)*, anyAttribute?)))
</extension>
iii. 例子:
Schema:
父類(lèi)型:
<xs:complexType name="basePerson">
<xs:choice>
<xs:element name="author" type="xs:string"/>
<xs:element name="character" type="xs:string"/>
</xs:choice>
</xs:complexType>
子類(lèi)型:
<xs:element name="person">
<xs:complexType>
<xs:complexContent>
<xs:extension base="basePerson">
<xs:sequence>
<xs:element name="editor" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
XML:
<person>
<author>…</author>
<editor>…</editor>
</person>
注:子類(lèi)型的定義等價(jià)于:
<xs:complexType name="person">
<xs:complexContent>
<xs:sequence>
<xs:choice>
<xs:element name="author" type="xs:string"/>
<xs:element name="character" type="xs:string"/>
</xs:choice>
<xs:sequence>
<xs:element name="editor" type="xs:string"/>
</xs:sequence>
</xs:sequence>
</xs:complexContent>
</xs:complexType>
d) Complex Content的約束(restriction)
i. 說(shuō)明:可以對基類(lèi)型中,已定義的內容和屬性進(jìn)行約束。通過(guò)修改元素的maxOccurs屬性,可以限制元素的出現,通過(guò)修改屬性的use屬性,可以限制屬性的出現。約束后的類(lèi)型是基類(lèi)型的子集。
ii. 語(yǔ)法:
<restriction
base = QName
id = ID
>
Content: (annotation?, (group | all | choice | sequence)?, ((attribute |
attributeGroup)*, anyAttribute?))
</restriction>
iii. 例子:
Schema:
父類(lèi)型:
<xs:complexType name="person">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="born" type="xs:string"/>
</xs:sequence>
<xs:attribute name="id" type="xs:string"/>
</xs:complexType>
子類(lèi)型:
<xs:element name="author">
<xs:complexType>
<xs:complexContent>
<xs:restriction base="person">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:element>
XML:
<author id="…">
<name>…</name>
</author>
注:通過(guò)約束得到新類(lèi)型時(shí),對于元素部分,我們需要重新書(shū)寫(xiě)我們需要的Content內容;
而對于屬性部分,我們只需要書(shū)寫(xiě)我們希望改變的部分,如果不需要改變,則可以不書(shū)寫(xiě)。
e) 兩種方法的比較
與擴展Simple Content的兩種方法相似,extension方法只能在父類(lèi)型的結尾部分增加新的節點(diǎn)或者屬性,而不能對父節點(diǎn)中的節點(diǎn)或屬性的類(lèi)型進(jìn)行修改。而restriction則可以通過(guò)重新書(shū)寫(xiě)Content和Attribute的方式,重新定義子類(lèi)型的各部分內容。另外,這兩種方法是非對稱(chēng)的,即通過(guò)一次extension和restriction不能得回到原來(lái)的類(lèi)型。對于使用擴展方法,符合擴展類(lèi)的XML文件內容,不一定符合基類(lèi)。而對于約束方法,符合擴展類(lèi)的XML內容,也必須符合基類(lèi)。
4. Mixed Content Complex Type
a) 說(shuō)明:我們能夠通過(guò)complexType聲明中的mixed屬性,定義Mixed Content Complex Type類(lèi)型。也能夠通過(guò)擴展和約束的方式,對Mixed Content Complex Type進(jìn)行擴展。
b) 通過(guò)mixed屬性定義Mixed Content Complex Type
i. 例子:
Schema:
<xs:element name="title">
<xs:complexType mixed="true">
<xs:choice>
<xs:element name="em" type="xs:token"/>
<xs:element name="a" type="xs:string"/>
</xs:choice>
<xs:attribute name="lang" type="xs:string"/>
</xs:complexType>
</xs:element>
XML:
<title lang="…">
…
<em>
…
</title>
c) Mixed Content的擴展(extention)
i. 例子:
Schema:
<xs:element name="title">
<xs:complexType mixed="true">
<xs:complexContent mixed="true">
<xs:extension base="…">
<xs:choice>
<xs:element name="strong" type="xs:string"/>
</xs:choice>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
d) Mixed Content的約束(restriction)
i. 例子:
Schema:
<xs:element name="title">
<xs:complexType mixed="true">
<xs:complexContent mixed="true">
<xs:restriction base="…">
<xs:choice>
<xs:element name="a" type="xs:string"/>
</xs:choice>
<xs:attribute name="lang"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:element>
e) Complex Content Complex Type和Mixed Content Complex Type之間的相互擴展
Complex -> Mixed(E) forbidden
Mixed -> Complex(E) forbidden
Complex -> Mixed(R) forbidden
Mixed -> Complex(R) ok
5. Empty Content Complex Type
a) 說(shuō)明:我們可以通過(guò)兩種方式來(lái)定義Empty Content,一種是通過(guò)禁止Simple Content Complex Type中的文本內容出現,另一種是通過(guò)禁止Complex Content Complex Type中的元素出現。
b) 通過(guò)Simple Content定義Empty Content
i. 例子:
Schema:
<xs:element name="br">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:enumeration value=""/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
c) 通過(guò)Complex Content定義Empty Content
i. 例子:
Schema:
<xs:element name="br">
<xs:complexType/>
</xs:element>
d) 對基于Simple Content的Empty Content進(jìn)行擴展和約束
由于是基于Simple Content的,所以在擴展時(shí),我們可以增加額外的屬性,而在約束時(shí)可以約束文本的內容。
e) 對基于Complex Content的Empty Content進(jìn)行擴展和約束
由于是基于Complex Content的,所以在擴展時(shí),我們可以增加額外的屬性和元素,而在
約束時(shí)可以約束屬性和元素的內容。
6. XML文檔結構抽象:
注:XML文檔的結構從抽象來(lái)說(shuō),就是E(元素節點(diǎn)),A(屬性節點(diǎn)),T(文本節點(diǎn))之間的一個(gè)組合關(guān)系。而根據這些節點(diǎn)的特性要求,他們的關(guān)系只能表現為以下幾種:屬性定義(A);空元素節點(diǎn)(E());元素節點(diǎn)包含屬性節點(diǎn)(E(A));元素節點(diǎn)包含文本節點(diǎn)(E(T));元素節點(diǎn)包含元素節點(diǎn)(E(E));元素節點(diǎn)包含元素節點(diǎn)和文本節點(diǎn)(E(A,T));元素節點(diǎn)包含元素節點(diǎn)和屬性節點(diǎn)(E(E,A));元素節點(diǎn)包含元素節點(diǎn)和文本節點(diǎn)(E(E,T));元素節點(diǎn)包含元素節點(diǎn),屬性節點(diǎn)和文本節點(diǎn)(E(E,A,T))。而DTD和Schema的作用就是定義這9中組合關(guān)系的規則。
7. 屬性定義(A)
a) 語(yǔ)法:
<attribute
default = string
fixed = string
form = (qualified | unqualified)
id = ID
name = NCName
ref = QName
type = QName
use = (optional | prohibited | required) : optional
>
Content: (annotation?, simpleType?)
</attribute>
b) 例子:
<attribute name="test" type="xs:string"/>
8. 空元素節點(diǎn)(E())
a) 語(yǔ)法:使用Empty Content Complex Type
b) 例子:
<xs:element name="test">
<xs:complexType/>
</xs:element>
9. 元素節點(diǎn)包含屬性節點(diǎn)(E(A))
a) 語(yǔ)法:使用Empty Content Complex Type
b) 例子:
<xs:element name="test">
<xs:complexType>
<attribute name="…" type="…"/>
</xs:complexType>
</xs:element>
10.元素節點(diǎn)包含文本節點(diǎn)(E(T))
a) 語(yǔ)法:使用Simple Content Complex Type
b) 例子:
<xs:element name="title">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string"/>
</xs:simpleContent>
</xs:complexType>
</xs:element>
11.元素節點(diǎn)包含元素節點(diǎn)(E(E))
a) 語(yǔ)法:使用Complex Content Complex Type
b) 例子:
<xs:complexType name="person">
<xs:complexContent>
<xs:sequence>
<xs:choice>
<xs:element name="author" type="xs:string"/>
<xs:element name="character" type="xs:string"/>
</xs:choice>
</xs:sequence>
</xs:complexContent>
</xs:complexType>
12.元素節點(diǎn)包含元素節點(diǎn)和文本節點(diǎn)(E(A,T))
a) 語(yǔ)法:使用Simple Content Complex Type
b) 例子:
<xs:element name="title">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="note" type="xs:token"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
13.元素節點(diǎn)包含元素節點(diǎn)和屬性節點(diǎn)(E(E,A))
a) 語(yǔ)法:使用Complex Content Complex Type
b) 例子:
<xs:element name="author">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="born" type="xs:string"/>
</xs:sequence>
<xs:attribute name="id" type="xs:string"/>
</xs:complexType>
</xs:element>
14.元素節點(diǎn)包含元素節點(diǎn)和文本節點(diǎn)(E(E,T))
a) 語(yǔ)法:使用Mixed Content Complex Type
b) 例子:
<xs:element name="title">
<xs:complexType mixed="true">
<xs:choice>
<xs:element name="em" type="xs:token"/>
<xs:element name="a" type="xs:string"/>
</xs:choice>
</xs:complexType>
</xs:element>
15.元素節點(diǎn)包含元素節點(diǎn),屬性節點(diǎn)和文本節點(diǎn)(E(E,A,T))
a) 語(yǔ)法:使用Mixed Content Complex Type
b) 例子:
<xs:element name="title">
<xs:complexType mixed="true">
<xs:choice>
<xs:element name="em" type="xs:token"/>
<xs:element name="a" type="xs:string"/>
</xs:choice>
<xs:attribute name="lang" type="xs:string"/>
</xs:complexType>
</xs:element>
<<<<<<<<::::::網(wǎng)友的相關(guān)評價(jià)及說(shuō)明信息::::::>>>>>>>>>
Schema Structure小結. 更新時(shí)間:2006-7-7 責任編輯:Jacky 資訊來(lái)源:網(wǎng)絡(luò )采集資訊作者:未知 閱讀次數: 次 ... Simple Type是Schema引入以表示葉子節點(diǎn)類(lèi)型的,而Complex Type是用來(lái)表示內部節點(diǎn)類(lèi)型的。因此,對于Simple Type我們關(guān)心的是她所允許的 ...
Schema Structure小結,XML/WML技術(shù)庫,網(wǎng)絡(luò )大本營(yíng)是一個(gè)專(zhuān)門(mén)發(fā)布編程資料,計算機相關(guān)技巧的大型網(wǎng)站,收集的資料非常之多,做中國最大的IT技術(shù)庫和編程數據庫!
<xs:choice>. <xs:element name="em" type="xs:token"/>. <xs:element name="a" type="xs:string"/>. </xs:choice>. <xs:attribute name="lang" type="xs:string"/>. </xs:complexType>. </xs:element>. 在百度搜索: Schema Structure小結 ...
Schema Structure小結. [本頁(yè)面推薦在1024x768分辯率下瀏覽] 文章類(lèi)別:Java. 網(wǎng)站目錄: 網(wǎng)站首頁(yè) ―> Java. 轉載自:www.csdn.net. 1. Schema機制:. a) Simple Type和Complex Type. 由于XML文檔被組織成樹(shù)狀結構,因此,我們可以按照節點(diǎn)所處的位置把 ...
Schema Structure小結. 作者:未知來(lái)源:月光軟件站加入時(shí)間:2005-2-28 月光軟件站. 1. Schema機制:. a) Simple Type和Complex Type. 由于XML文檔被組織成樹(shù)狀結構,因此,我們可以按照節點(diǎn)所處的位置把他們區分為葉子節點(diǎn)和內部節點(diǎn)。 ...
Schema Structure小結. 本文Tag:xml complextype schema xs 節點(diǎn) ... 使用與命名空間 · XML Schema學(xué)習教程(二)-元素屬性的定義與約束 · 學(xué)習筆記--xml schema · XML Schema Part 1: Structures Second Edition · W3C XML 架構設計模式:避免復雜性 ...
1.Schema機制:a)SimpleType和ComplexType由于XML文檔被組織成樹(shù)狀結構,因此,我們可以按照節點(diǎn)所處的位置把他們區分為葉子節點(diǎn)和內部節點(diǎn)。SimpleType是Schema引入以表示葉子節點(diǎn)類(lèi)型的,而ComplexType是用來(lái)表示內部節點(diǎn)類(lèi)型的。
Schema Structure小結. 1. Schema機制:. a) Simple Type和Complex Type. 由于XML文檔被組織成樹(shù)狀結構,因此,我們可以按照節點(diǎn)所處的位置把他們區分為葉子節點(diǎn)和內部節點(diǎn)。Simple Type是Schema引入以表示葉子節點(diǎn)類(lèi)型的,而Complex Type是用來(lái)表示內部 ...
資料:Schema Structure小結. ... Simple Type是Schema引入以表示葉子節點(diǎn)類(lèi)型的,而Complex Type是用來(lái)表示內部節點(diǎn)類(lèi)型的。 ... Schema定義的Compositor包括:sequence,choice,all;Partical包括:element,sequence,choice,any和group。 ...
Schema Structure小結. 出處:統一教學(xué)網(wǎng); 作者:nickcen; 編輯:N/A; 發(fā)表日期:2006-6-25 15:33:00. 1. Schema機制:. a) Simple Type和Complex Type. 由于XML文檔被組織成樹(shù)狀結構,因此,我們可以按照節點(diǎn)所處的位置把他們區分為葉子節點(diǎn)和內部節點(diǎn) ...