Schema指示器(Indicators)
用指示器(Indicators)我們可以控制檔案中元素的使用方法,有七種指示器:
1、順序指示器:All、Choice、Sequence;
2、出現次數指示器:maxOccurs 、minOccurs;
3、組指示器:Groupname、attributeGroup name;
-
順序指示器(Indicators)用於指定元素的順序
<all>指示器(Indicators)指明瞭子元件可以以任何次序出現,並且每個子元件只能出現一次:1
<
xs:element
name
=
"Author"
>
2
<
xs:complexType
>
3
<
xs:all
>
4
<
xs:element
name
=
"firstname"
type
=
"xs:string"
/>
5
<
xs:element
name
=
"lastname"
type
=
"xs:string"
/>
6
</
xs:all
>
7
</
xs:complexType
>
8
</
xs:element
>
1
<
xs:element
name
=
"Author"
>
2
<
xs:complexType
>
3
<
xs:choice
>
4
<
xs:element
name
=
"firstname"
type
=
"xs:string"
/>
5
<
xs:element
name
=
"lastname"
type
=
"xs:string"
/>
6
</
xs:choice
>
7
</
xs:complexType
>
8
</
xs:element
>
1
<
xs:element
name
=
"Author"
>
2
<
xs:complexType
>
3
<
xs:sequence
>
4
<
xs:element
name
=
"firstname"
type
=
"xs:string"
/>
5
<
xs:element
name
=
"lastname"
type
=
"xs:string"
/>
6
</
xs:sequence
>
7
</
xs:complexType
>
8
</
xs:element
>
-
出現的次數指示器:
最多出現次數指示器(Indicators)指明瞭一個元素可以出現的最多次數;最少出現次數指示器(Indicators)指明瞭一個元素要出現的最小次數:1
<
xs:element
name
=
"Author"
>
2
<
xs:complexType
>
3
<
xs:sequence
>
4
<
xs:element
name
=
"firstname"
type
=
"xs:string"
minOccurs
=
"0"
/>
5
<
xs:element
name
=
"lastname"
type
=
"xs:string"
maxOccurs
=
"2"
/>
6
</
xs:sequence
>
7
</
xs:complexType
>
8
</
xs:element
>
-
組指示器(Indicators)用於定義相關的元素組:
1、元素組:你必須在組宣告裡定義一個all, choice,或sequence元素。下面的例子定義了一個名為"persongroup"的組:屬性組宣告好以後,我們可以這樣引用:1
<
xs:group
name
=
"persongroup"
>
2
<
xs:sequence
>
3
<
xs:element
name
=
"firstname"
/>
4
<
xs:element
name
=
"lastname"
/>
5
</
xs:sequence
>
6
</
xs:group
>
01
<
xs:group
name
=
"persongroup"
>
02
<
xs:sequence
>
03
<
xs:element
name
=
"firstname"
/>
04
<
xs:element
name
=
"lastname"
/>
05
</
xs:sequence
>
06
</
xs:group
>
07
08
<
xs:element
name
=
"person"
type
=
"personinfo"
></
xs:element
>
09
<
xs:complexType
name
=
"personinfo"
>
10
<
xs:sequence
>
11
<
xs:group
ref
=
"persongroup"
/>
12
<
xs:element
name
=
"country"
type
=
"xs:string"
/>
13
</
xs:sequence
>
14
</
xs:complexType
>
1
<
xs:attributeGroup
name
=
"personattrgroup"
>
2
<
xs:attribute
name
=
"firstname"
type
=
"xs:string"
/>
3
<
xs:attribute
name
=
"lastname"
type
=
"xs:string"
/>
4
<
xs:attribute
name
=
"birthday"
type
=
"xs:date"
/>
5
</
xs:attributeGroup
>
01
<
xs:attributeGroup
name
=
"personattrgroup"
>
02
03
<
xs:attribute
name
=
"firstname"
type
=
"xs:string"
/>
04
<
xs:attribute
name
=
"lastname"
type
=
"xs:string"
/>
05
<
xs:attribute
name
=
"birthday"
type
=
"xs:date"
/>
06
07
</
xs:attributeGroup
>
08
<
xs:element
name
=
"person"
>
09
<
xs:complexType
>
10
<
xs:attributeGroup
ref
=
"personattrgroup"
/>
11
</
xs:complexType
>
12
13
</
xs:element
>
其他:
<any>元素可以使我們在XML文件中新增沒有被schema 定義過的新元素從而擴充XML文件;
<anyAttribute>元素可使我們在XML文件中新增未被schema指定過的屬性;
01 |
< xs:element name = "person" > |
02 |
< xs:complexType > |
03 |
< xs:sequence > |
04 |
< xs:element name = "firstname" type = "xs:string" /> |
05 |
06 |
< xs:element name = "lastname" type = "xs:string" /> |
07 |
< xs:any minOccurs = "0" /> |
08 |
</ xs:sequence > |
09 |
</ xs:complexType > |
10 |
11 |
</ xs:element > |
我們可以在"person"元素的內容裡擴充任意元素(在<lastname>的後面);
請看下面名為"children.xsd"的schema檔案:
01 |
<? xml version = "1.0" encoding = "ISO-8859-1" ?> |
02 |
03 |
< xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema" |
04 |
targetNamespace = "http://www.w3schools.com" |
05 |
xmlns = "http://www.w3schools.com" |
06 |
elementFormDefault = "qualified" > |
07 |
< xs:element name = "children" > |
08 |
< xs:complexType > |
09 |
10 |
< xs:sequence > |
11 |
< xs:element name = "childname" type = "xs:string" |
12 |
maxOccurs = "unbounded" /> |
13 |
</ xs:sequence > |
14 |
15 |
</ xs:complexType > |
16 |
</ xs:element > |
17 |
</ xs:schema > |
下面的XML檔案(叫做"Myfamily.xml"),用上了來自"family.xsd" 和"children.xsd"兩篇不同schema的元件:
01 |
<? xml version = "1.0" encoding = "ISO-8859-1" ?> |
02 |
< persons xmlns = "http://www.microsoft.com" |
03 |
04 |
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" |
05 |
xsi:SchemaLocation="http://www.microsoft.com family.xsd |
06 |
http://www.w3schools.com children.xsd"> |
07 |
< person > |
08 |
< firstname >Hege</ firstname > |
09 |
< lastname >Refsnes</ lastname > |
10 |
11 |
< children > |
12 |
< childname >Cecilie</ childname > |
13 |
</ children > |
14 |
</ person > |
15 |
< person > |
16 |
< firstname >Stale</ firstname > |
17 |
18 |
< lastname >Refsnes</ lastname > |
19 |
</ person > |
20 |
</ persons > |
<any> 和<anyAttribute>元素是用於製造可擴充套件文件的!它們允許文件含有沒有在主要XML schema裡宣告過的其它新元素。
元素替代:substitutionGroup
1 |
< xs:element
name = "name"
type = "xs:string" /> |
2 |
< xs:element
name = "navn"
substitutionGroup = "name" /> |
3 |
< xs:complexType
name = "custinfo" > |
4 |
< xs:sequence > |
5 |
< xs:element
ref = "name" /> |
6 |
</ xs:sequence > |
7 |
</ xs:complexType > |
8 |
< xs:element
name = "customer"
type = "custinfo" /> |
9 |
< xs:element
name = "kunde"
substitutionGroup = "customer" /> |
1 |
< customer > |
2 |
< name >John
Smith</ name > |
3 |
4 |
</ customer > |
1 |
< kunde > |
2 |
3 |
< navn >John
Smith</ navn > |
4 |
</ kunde > |
關閉替代元素:為了防止其他元素被已指定的元素替代(Element Substitution),可以用block屬性;
1 |
< xs:element name = "name" type = "xs:string" block = "substitution" /> |
1、可替代元素型別應和標題元素的型別相同,或是從中派生出來的。如果可替代元素型別和標題元素的型別相同,你就不需要再指明可替代元素的型別了;
2、可替代元素組裡的所有元素(標題元素和可替代元素)必須宣告為“全域元素(global element)”,否則它是不會作用的;
“全域元素”是"schema"元素下面的直接子元素。“本地元素”是巢狀在別的元素裡的元素
相關文章
- 自定義ViewPager指示器Viewpager
- c# 索引指示器C#索引
- SwiftUI 簡明教程之指示器SwiftUI
- C#筆記----------------------------索引指示器C#筆記索引
- PostgreSQL:Schema 管理SQL
- MySQL Performance SchemaMySqlORM
- oracle schema物件Oracle物件
- WM Define Storage Type Indicators定義儲存型別識別符號(八)Indicator型別符號
- Json Schema簡介和Json Schema的.net實現庫 LateApexEarlySpeed.Json.SchemaJSON
- 小程式輪播圖自定義指示器
- CSS Scroll Indicator —— 純CSS 滾動指示器CSSIndicator
- MySQL 5.7 SYS SCHEMAMySql
- Flutter-帶動畫的指示器anim_indicatorFlutter動畫Indicator
- Oracle資料庫的“健康指示器”——事件(events)Oracle資料庫事件
- Win10怎麼開啟游標指示器_win10開啟文字游標指示器的圖文教程Win10
- API Schema in kubernetesAPI
- 表的schema 檔案
- MySQL Performance Schema詳解MySqlORM
- Understanding JSON SchemaJSON
- oracle中schema的概念Oracle
- DBMS_UTILITY.ANALYZE_SCHEMA
- SQL can execute in wrong SchemaSQL
- Resolution of Schema Object Dependencies (241)Object
- 建立REST SOE的schemaREST
- Flutter 基礎控制元件篇-->進度指示器Flutter控制元件
- Apache Avro & Avro Schema簡介ApacheVR
- performance_schema詳解一ORM
- information_schema的結構ORM
- oracle中schema指的是什麼?Oracle
- 資料模式(Schema)定義模式
- Performance Schema使用簡介(一)ORM
- 深入淺出 FlatBuffers 之 Schema
- MySQL 5.7 Performance Schema 介紹MySqlORM
- XML - Schema之基礎示例XML
- oracle中schema指的是什麼? .Oracle
- DB2刪除schemaDB2
- DBMS_UTILITY.COMPILE_SCHEMACompile
- user和schema的區別