XML 学习笔记 7:XSD
本文章内容参考自:
W3school XSD 教程
Extensible Markup Language (XML) 1.0 (Second Edition)
XML Schema 2001
XML Schema Part 2: Datatypes Second Edition
文章目录
- 1、XSD 是什么
- 2、XSD 内置数据类型 - built-in datatypes
- 2.1、基本数据类型 19 种
- 2.1.1、基本字符串类型 1 种
- 2.1.1.1、字符串 - string 简单类型
- 2.1.2、基本数值类型 3 种
- 2.1.2.1、十进制数 - decimal 简单类型
- 2.1.2.2、单精度浮点数 - float 简单类型
- 2.1.2.3、双精度浮点数 - double 简单类型
- 2.1.3、日期时间类型 9 种
- 2.1.3.1、日期 - date 简单类型
- 2.1.3.2、时间 - time 简单类型
- 2.1.3.3、日期时间 - dateTime 简单类型
- 2.1.3.4、年 - gYear 简单类型
- 2.1.3.5、年和月 - gYearMonth 简单类型
- 2.1.3.6、月 - gMonth 简单类型
- 2.1.3.7、月和天 - gMonthDay 简单类型
- 2.1.3.8、天 - gDay 简单类型
- 2.1.3.9、周期 - duration 简单类型
- 2.1.4、布尔类型 1 种
- 2.1.4.1、布尔 - boolean 简单类型
- 2.1.5、编码二进制类型 2 种
- 2.1.5.1、Base64 编码 - base64Binary 简单类型
- 2.1.5.2、十六进制编码 - hexBinary 简单类型
- 2.1.6、其他基本数据类型 3 种
- 2.1.6.1、统一资源标识符 - URI 简单类型
- 2.1.6.2、限定名 - QName 简单类型
- 2.1.6.3、实体标记 - NOTATION 简单类型
- 2.2、派生数据类型 25 种
- 2.2.1、派生字符串类型 12 种
- 2.2.1.1、名称标记 - NMTOKEN 简单类型
- 2.2.1.2、用户定义名称 - NCName 简单类型
- 2.2.1.3、实体 - ENTITIE 简单类型
- 2.2.2、派生数值类型 13 种
- 3、派生类型
- 3.1、扩展派生类型 - extension 元素
- 3.2、限制派生类型 - restrictionType 复合类型
- 3.3、简单类型的扩展和限制
- 3.4、复合类型的扩展和限制
- 3.5、集合派生类型
- 4、XSD 简单类型
- 4.1、简单元素
- 4.2、属性 - attribute
- 4.3、限定 12 种 - facet 类型
- 4.3.1、有序限定 4 种
- 4.3.1.1、左开区间 - minExclusive 元素
- 4.3.1.2、左闭区间 - minInclusive 元素
- 4.3.1.3、右开区间 - maxExclusive 元素
- 4.3.1.4、右闭区间 - maxInclusive 元素
- 4.3.2、数值限定 5 种
- 4.3.2.1、总位数 - totalDigits 元素
- 4.3.2.2、小数位数 - fractionDigits 元素
- 4.3.2.3、长度 - length 元素
- 4.3.2.4、最小长度 - minLength 元素
- 4.3.2.5、最大长度 - maxLength 元素
- 4.3.3、非固定值限定 2 种
- 4.3.3.1、枚举值限定 - enumeration 元素
- 4.3.3.2、字符串匹配模式 - pattern 元素
- 4.3.4、空白字符限定 1 种
- 4.3.4.1、空白字符处理 - whiteSpace 元素
- 5、XSD 复合类型
- 复合类型指示器
- Occurrence 指示器 - occurs 属性组
- minOccurs 属性
- maxOccurs 属性
- Order 指示器 - explicitGroup 复合类型
- choice 元素和 sequence 元素
- all 元素
- Group 指示器
- 元素组 - realGroup 复合类型
- 属性组 - attributeGroup 复合类型
- 复合元素
- 通配符类型 - wildcard 复合类型
- 任何元素 - any 元素
- 任何属性 - anyAttribute 元素
- 注释 - annotation 元素
1、XSD 是什么
XSD(XML Schema Definition)用来描述 XML 文档的结构,是 DTD 的替代者,功能比 DTD 更强大。
-
XML Schema 基于 XML 编写
- 可扩展
- 可以通过 XML 解析器来解析 Schema 文件
- 可以通过 XML DOM 来处理 Schema
- 可以通过 XSLT 来转换 Schema
-
XML Schema 支持数据类型
- 可更容易地验证数据的正确性
- 可以更容易地定义数据格式
- 可以更容易地定义数据约束(data facets)
- 可以更容易地在不同的数据类型间转换数据
通过 XML Schema,数据的发送方可以用一种接收方能够理解的方式来描述数据。
例如 “03-11-2004”,在某些国家被解释为 11 月 3 日,而在另一些国家被解释为 3 月 11 日。
但是一个带有数据类型的 XML 元素 <date type="date">2004-03-11</date>
,可以确保对数据内容的一致理解,这是因为 XML 数据类型 xs:date
要求的格式是 YYYY-MM-DD
。
XML Schema 在 2001 年 5 月 2 日成为 W3C 标准。
2、XSD 内置数据类型 - built-in datatypes
XSD 规定 schema 的数据类型包括 44 种内置的数据类型(built-in datatypes)和用户派生的数据类型(user-derived datatypes)。
44 种内置类型包括 19 种从 anySimpleType
派生的基本类型(primitive datatypes)和 25 种从基本类型派生的派生基本类型(derived primitive types)。
19 种基本类型包括:
- 1 种字符串类型 string
- 3 种数值类型 decimal、float、double
- 9 种日期时间类型 date、time、datetime、gYear、gYearMonth、gMonth、gMonthDay、gDay 以及周期类型 duration
- 1 种布尔类型 boolean
- 2 种编码二进制类型 base64Binary、hexBinary
- 3 种其他类型 anyURI、QName、NOTATION
25 种派生类型又包括 12 种字符串派生类型以及 13 种数值派生类型。如下图示:
2.1、基本数据类型 19 种
2.1.1、基本字符串类型 1 种
数据类型 | 派生类型 | 限制 | 描述 |
---|---|---|---|
xs:string | anySimpleType 类型 | whiteSpace="preserve" | 字符串。XML 处理器不会做任何处理,保留空格、换行、回车以及制表符 |
2.1.1.1、字符串 - string 简单类型
2.1.2、基本数值类型 3 种
数据类型 | 派生类型 | 限制 | 描述 |
---|---|---|---|
xs:decimal | anySimpleType 类型 | whiteSpace="collapse"、fixed="true" | 十进制 数。最大位数是 18 位。例如 -999.52 |
xs:float | anySimpleType 类型 | whiteSpace="collapse"、fixed="true" | 32 位单精度浮点数 |
xs:double | anySimpleType 类型 | whiteSpace="collapse"、fixed="true" | 64 位双精度浮点数 |
2.1.2.1、十进制数 - decimal 简单类型
2.1.2.2、单精度浮点数 - float 简单类型
2.1.2.3、双精度浮点数 - double 简单类型
2.1.3、日期时间类型 9 种
数据类型 | 派生类型 | 限制 | 描述 |
---|---|---|---|
xs:date | anySimpleType 类型 | whiteSpace="collapse"、fixed="true" | YYYY-MM-DD |
xs:time | anySimpleType 类型 | whiteSpace="collapse"、fixed="true" | hh:mm:ss |
xs:dateTime | anySimpleType 类型 | whiteSpace="collapse"、fixed="true" | YYYY-MM-DDThh:mm:ss ,T 表示时间部分的起始 |
xs:gYear | anySimpleType 类型 | whiteSpace="collapse"、fixed="true" | 定义日期时间的一个部分 - 年 (YYYY) |
xs:gYearMonth | anySimpleType 类型 | whiteSpace="collapse"、fixed="true" | 定义日期时间的一个部分 - 年和月 (YYYY-MM) |
xs:gMonth | anySimpleType 类型 | whiteSpace="collapse"、fixed="true" | 定义日期时间的一个部分 - 月 (MM) |
xs:gMonthDay | anySimpleType 类型 | whiteSpace="collapse"、fixed="true" | 定义日期时间的一个部分 - 月和天 (MM-DD) |
xs:gDay | anySimpleType 类型 | whiteSpace="collapse"、fixed="true" | 定义日期时间的一个部分 - 天 (DD) |
xs:duration | anySimpleType 类型 | whiteSpace="collapse"、fixed="true" | PnYnMnDTnHnMnS ,n 表示年月日时分秒的数目,P 表示周期,T 表示时间部分的起始 。例如 P5Y2M10DT15H 表示 5 年零 2 个月零 10天 零 15 小时 |
2.1.3.1、日期 - date 简单类型
2.1.3.2、时间 - time 简单类型
2.1.3.3、日期时间 - dateTime 简单类型
2.1.3.4、年 - gYear 简单类型
<xs:simpleType name="gYear" id="gYear"><xs:annotation><xs:appinfo><hfp:hasFacet name="pattern"/><hfp:hasFacet name="enumeration"/><hfp:hasFacet name="whiteSpace"/><hfp:hasFacet name="maxInclusive"/><hfp:hasFacet name="maxExclusive"/><hfp:hasFacet name="minInclusive"/><hfp:hasFacet name="minExclusive"/><hfp:hasProperty name="ordered" value="partial"/><hfp:hasProperty name="bounded" value="false"/><hfp:hasProperty name="cardinality" value="countably infinite"/><hfp:hasProperty name="numeric" value="false"/></xs:appinfo><xs:documentation source="http://www.w3.org/TR/xmlschema-2/#gYear"/></xs:annotation><xs:restriction base="xs:anySimpleType"><xs:whiteSpace value="collapse" fixed="true" id="gYear.whiteSpace"/></xs:restriction>
</xs:simpleType>
[Definition]
gYear
represents a gregorian calendar year. The ·value space· of gYear is the set of Gregorian calendar years as defined in § 5.2.1 of [ISO 8601]
. Specifically, it is a set of one-year long, non-periodic instances
e.g. lexical 1999 to represent the whole year 1999, independent of how many months and days this year has.
gYear 表示公历年。gYear 的值空间是 ISO 8601 中定义的一组公历年份。具体来说,它是一组一年长的非周期实例。例如词汇 1999,代表 1999 年全年,与该年的月份和天数无关。
2.1.3.5、年和月 - gYearMonth 简单类型
2.1.3.6、月 - gMonth 简单类型
2.1.3.7、月和天 - gMonthDay 简单类型
2.1.3.8、天 - gDay 简单类型
2.1.3.9、周期 - duration 简单类型
2.1.4、布尔类型 1 种
数据类型 | 派生类型 | 限制 | 描述 |
---|---|---|---|
xs:boolean | anySimpleType 类型 | whiteSpace="collapse"、fixed="true" | true 或 false |
2.1.4.1、布尔 - boolean 简单类型
2.1.5、编码二进制类型 2 种
数据类型 | 派生类型 | 限制 | 描述 |
---|---|---|---|
xs:base64Binary | anySimpleType 类型 | whiteSpace="collapse"、fixed="true" | Base64 编码 的二进制数据 |
xs:hexBinary | anySimpleType 类型 | whiteSpace="collapse"、fixed="true" | 十六进制编码 的二进制数据 |
2.1.5.1、Base64 编码 - base64Binary 简单类型
2.1.5.2、十六进制编码 - hexBinary 简单类型
2.1.6、其他基本数据类型 3 种
数据类型 | 派生类型 | 限制 | 描述 |
---|---|---|---|
xs:anyURI | anySimpleType 类型 | whiteSpace="collapse"、fixed="true" | 转义 URI |
xs:QName | anySimpleType 类型 | whiteSpace="collapse"、fixed="true" | 由命名空间名称和本地名称组成 的限定名 |
xs:NOTATION | anySimpleType 类型 | whiteSpace="collapse"、fixed="true" | 非 XML 格式的数据 |
2.1.6.1、统一资源标识符 - URI 简单类型
2.1.6.2、限定名 - QName 简单类型
<xs:simpleType name="QName" id="QName"><xs:annotation><xs:appinfo><hfp:hasFacet name="length"/><hfp:hasFacet name="minLength"/><hfp:hasFacet name="maxLength"/><hfp:hasFacet name="pattern"/><hfp:hasFacet name="enumeration"/><hfp:hasFacet name="whiteSpace"/><hfp:hasProperty name="ordered" value="false"/><hfp:hasProperty name="bounded" value="false"/><hfp:hasProperty name="cardinality" value="countably infinite"/><hfp:hasProperty name="numeric" value="false"/></xs:appinfo><xs:documentation source="http://www.w3.org/TR/xmlschema-2/#QName"/></xs:annotation><xs:restriction base="xs:anySimpleType"><xs:whiteSpace value="collapse" fixed="true" id="QName.whiteSpace"/></xs:restriction>
</xs:simpleType>
[Definition]
QName
represents XML qualified names. The value space of QName is the set of tuples {namespace name, local part}
, where namespace name is an anyURI and local part is an NCName. The lexical space of QName is the set of strings that match the QName production of [Namespaces in XML]
.
限定名称由命名空间名称和本地部分组成,命名空间名称是任意 URI,而本地部分则是由用户定义的名称(NCName,non-colonized Name)。
2.1.6.3、实体标记 - NOTATION 简单类型
<xs:simpleType name="NOTATION" id="NOTATION"><xs:annotation><xs:appinfo><hfp:hasFacet name="length"/><hfp:hasFacet name="minLength"/><hfp:hasFacet name="maxLength"/><hfp:hasFacet name="pattern"/><hfp:hasFacet name="enumeration"/><hfp:hasFacet name="whiteSpace"/><hfp:hasProperty name="ordered" value="false"/><hfp:hasProperty name="bounded" value="false"/><hfp:hasProperty name="cardinality" value="countably infinite"/><hfp:hasProperty name="numeric" value="false"/></xs:appinfo><xs:documentation source="http://www.w3.org/TR/xmlschema-2/#NOTATION"/></xs:annotation><xs:restriction base="xs:anySimpleType"><xs:whiteSpace value="collapse" fixed="true" id="NOTATION.whiteSpace"/></xs:restriction>
</xs:simpleType>
[Definition : Notations identify by name the format of unparsed entities, the format of elements which bear a notation attribute, or the application to which a processing instruction is addressed.]
NOTATION 通过名称标识:
- 未解析实体的格式
- 能够帮助 XML 处理器处理实体的外部应用程序
Schema Component Constraint: enumeration facet value required for NOTATION
It is an error for NOTATION to be used directly in a schema. Only datatypes that are derived from NOTATION by specifying a value for enumeration can be used in a schema.
在 schema 中直接使用 NOTATION 类型是不合法的,只能使用通过 enumeration 限制派生后的类型。
例如:
<xs:notation name="gif" public="image/gif" system="view.exe"/>
<xs:notation name="jpeg" public="image/jpeg" system="view.exe"/><xs:element name="image"><xs:complexType><xs:simpleContent><xs:attribute name="type"><xs:simpleType><xs:restriction base="xs:NOTATION"><xs:enumeration value="gif"/><xs:enumeration value="jpeg"/><xs:restriction></xs:simpleType></xs:attribute></xs:simpleContent></xs:complexType>
</xs:element><image type="gif"></image>
2.2、派生数据类型 25 种
2.2.1、派生字符串类型 12 种
数据类型 | 派生类型 | 限制 | 描述 |
---|---|---|---|
xs:normalizedString | string 类型 | whiteSpace="replace" | 规范化字符串。XML 处理器会移除制表符、换行以及回车 |
xs:token | normalizedString 类型 | whiteSpace="collapse" | 标记。XML 处理器会移除制表符、换行、回车以及开头和结尾的空格,多个连续空格的内部序列会被缩减为一个空格 |
xs:language | token 类型 | pattern="[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*" | 由 RFC3066 规定的合法的语言标识 |
xs:NMTOKEN | token 类型 | pattern="\c+" ,\c 表示NameChar | 名称标记 |
xs:NMTOKENS | NMTOKEN 集合 | list itemType="xs:NMTOKEN"、minLength=1 | 名称标记集合 |
xs:Name | token 类型 | pattern="\i\c*" ,\i 表示 NameStartChar,\c 表示 NameChar | 名称 |
xs:NCName | Name 类型 | pattern="[\i-[:]][\c-[:]]*" ,\i 表示 NameStartChar,\c 表示NameChar | “non-colonized” Name,即用户定义名称 |
xs:ID | NCName 类型 | 唯一标识 | |
xs:IDREF | NCName 类型 | 唯一标识引用 | |
xs:IDREFS | IDREF 集合 | list itemType="xs:IDREF"、minLength=1 | 唯一标识引用集合 |
xs:ENTITIE | NCName 类型 | 实体 | |
xs:ENTITIES | ENTITY 集合 | list itemType="xs:ENTITY"、minLength=1 | 实体集合 |
2.2.1.1、名称标记 - NMTOKEN 简单类型
<xs:simpleType name="NMTOKEN" id="NMTOKEN"><xs:annotation><xs:documentation source="http://www.w3.org/TR/xmlschema-2/#NMTOKEN"/></xs:annotation><xs:restriction base="xs:token"><xs:pattern value="\c+" id="NMTOKEN.pattern"><xs:annotation><xs:documentation source="http://www.w3.org/TR/REC-xml#NT-Nmtoken">pattern matches production 7 from the XML spec</xs:documentation></xs:annotation></xs:pattern></xs:restriction>
</xs:simpleType>
pattern:
[4] NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
[4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
[5] Name ::= NameStartChar (NameChar)*
[6] Names ::= Name (#x20 Name)*
[7] Nmtoken ::= (NameChar)+
[8] Nmtokens ::= Nmtoken (#x20 Nmtoken)*
2.2.1.2、用户定义名称 - NCName 简单类型
<xs:simpleType name="NCName" id="NCName"><xs:annotation><xs:documentation source="http://www.w3.org/TR/xmlschema-2/#NCName"/></xs:annotation><xs:restriction base="xs:Name"><xs:pattern value="[\i-[:]][\c-[:]]*" id="NCName.pattern"><xs:annotation><xs:documentation source="http://www.w3.org/TR/REC-xml-names/#NT-NCName">pattern matches production 4 from the Namespaces in XML spec</xs:documentation></xs:annotation></xs:pattern></xs:restriction>
</xs:simpleType>
2.2.1.3、实体 - ENTITIE 简单类型
2.2.2、派生数值类型 13 种
数据类型 | 描述 |
---|---|
xs:integer | 由 fractionDigits=0、pattern="[\-+]?[0-9]+" 限制 ,从 decimal 派生 的整数,用于规定无小数部分 的数值 |
xs:nonPositiveInteger | 由 maxInclusive=0 限制 ,从 integer 派生 的非正整数(0 和负整数) |
xs:negativeInteger | 负整数 |
xs:long | 由 minInclusive、maxInclusive 限制 ,从 integer 派生 的有正负 的 64 位整数 |
xs:int | 有正负的 32 位整数 |
xs:short | 有正负的 16 位整数 |
xs:byte | 有正负的 8 位整数 |
xs:nonNegativeInteger | 非负整数(0 和正整数) |
xs:positiveInteger | 正整数 |
xs:unsignedLong | 无正负 的 64 位整数 |
xs:unsignedInt | 无正负的 32 位整数 |
xs:unsignedShort | 无正负的 16 位整数 |
xs:unsignedByte | 无正负的 8 位整数 |
3、派生类型
3.1、扩展派生类型 - extension 元素
类型扩展即 extension
元素,定义对简单类型 simpleType
或复合类型 simpleContent
、complexContent
的扩展,也就是为类型添加新的元素或属性。
<extension
id=ID
base=QName
any attributes
>(annotation?,((group|all|choice|sequence)?,((attribute|attributeGroup)*,anyAttribute?)))
</extension>
使用扩展定义一个复合类型 Chinese_customer
,它从复合类型 customer
派生,拥有新的子元素 country
:
<xs:complexType name="customer"><xs:sequence><xs:element name="name" type="xs:string"/></xs:sequence>
</xs:complexType><xs:complexType name="Chinese_customer"><xs:complexContent><xs:extension base="customer"><xs:sequence><xs:element name="country" type="xs:string"/></xs:sequence></xs:extension></xs:complexContent>
</xs:complexType>
3.2、限制派生类型 - restrictionType 复合类型
<xs:complexType name="restrictionType"><xs:complexContent><xs:extension base="xs:annotated"><xs:sequence><xs:choice minOccurs="0"><xs:group ref="xs:typeDefParticle"/><xs:group ref="xs:simpleRestrictionModel"/></xs:choice><xs:group ref="xs:attrDecls"/></xs:sequence><xs:attribute name="base" type="xs:QName" use="required"/></xs:extension></xs:complexContent>
</xs:complexType>
类型限制即 restriction
元素,定义对简单类型 simpleType
或复合类型 simpleContent
、complexContent
的约束,并不会为类型添加新的元素或属性。
<restriction
id=ID
base=QName
any attributes
><!-- Content for simpleType -->(annotation?,(simpleType?,(minExclusive|minInclusive|maxExclusive|maxInclusive|totalDigits|fractionDigits|length|minLength|maxLength|enumeration|whiteSpace|pattern)*))<!-- Content for simpleContent -->(annotation?,(simpleType?,(minExclusive |minInclusive|maxExclusive|maxInclusive|totalDigits|fractionDigits|length|minLength|maxLength|enumeration|whiteSpace|pattern)*)?, ((attribute|attributeGroup)*,anyAttribute?))<!-- Content for complexContent -->(annotation?,(group|all|choice|sequence)?,((attribute|attributeGroup)*,anyAttribute?))
</restriction>
例如使用约束定义一个复合类型 Chinese_customer
,它从复合类型 customer
派生,子元素 country
的固定值是 “China”:
<xs:complexType name="customer"><xs:sequence><xs:element name="name" type="xs:string"/><xs:element name="country" type="xs:string"/></xs:sequence>
</xs:complexType><xs:complexType name="Chinese_customer"><xs:complexContent><xs:restriction base="customer"><xs:sequence><xs:element name="name" type="xs:string"/><xs:element name="country" type="xs:string" fixed="China"/></xs:sequence></xs:restriction></xs:complexContent>
</xs:complexType>
3.3、简单类型的扩展和限制
simpleContent
元素是对简单类型 simpleType
元素的扩展或限制,简单类型扩展后会变成复合类型。
<xs:element name="simpleContent" id="simpleContent"><xs:annotation><xs:documentation source="http://www.w3.org/TR/xmlschema-1/#element-simpleContent"/></xs:annotation><xs:complexType><xs:complexContent><xs:extension base="xs:annotated"><xs:choice><xs:element name="restriction" type="xs:simpleRestrictionType"/><xs:element name="extension" type="xs:simpleExtensionType"/></xs:choice></xs:extension></xs:complexContent></xs:complexType>
</xs:element>
例如对简单类型 integer
进行扩展后获得一个复合类型 shoesize
,其内容被定义为整数数据类型,并包含一个 country
属性:
<xs:element name="shoesize"><xs:complexType><xs:simpleContent><xs:extension base="xs:integer"><xs:attribute name="country" type="xs:string" /></xs:extension></xs:simpleContent></xs:complexType>
</xs:element>
3.4、复合类型的扩展和限制
complexContent
元素定义对复合类型 complexType
元素的扩展或限制。
<xs:element name="complexContent" id="complexContent"><xs:annotation><xs:documentation source="http://www.w3.org/TR/xmlschema-1/#element-complexContent"/></xs:annotation><xs:complexType><xs:complexContent><xs:extension base="xs:annotated"><xs:choice><xs:element name="restriction" type="xs:complexRestrictionType"/><xs:element name="extension" type="xs:extensionType"/></xs:choice><xs:attribute name="mixed" type="xs:boolean"/></xs:extension></xs:complexContent></xs:complexType>
</xs:element>
3.5、集合派生类型
4、XSD 简单类型
simpleType
元素定义一个简单类型,规定与
- 仅包含文本内容的元素
- 或 属性 的值有关的信息
- 以及对它们的 约束
<simpleType id=ID name=NCName anyAttribute>(annotation?,(restriction|list|union))
</simpleType>
例如声明 age
元素是一个带有约束(restriction)的简单类型(age
元素的值不能小于 0 或大于 100):
<xs:element name="age"><xs:simpleType><xs:restriction base="xs:integer"><xs:minInclusive value="0"/><xs:maxInclusive value="100"/></xs:restriction></xs:simpleType>
</xs:element>
4.1、简单元素
简单元素指那些仅包含文本内容的元素,它不包含任何其他的元素或属性。
不过,“仅包含文本内容” 这个限定却很容易造成误解。文本内容有很多种类型,它可以是 XML Schema 定义类型中的一种(布尔、字符串、数值等),它也可以是自定义的定制类型。
可以向数据类型添加限定(facets),以此来限制它的内容,或者可以要求数据匹配某种特定的模式(facets 中的 pattern)。
<xs:element name="元素名称" type="数据类型" default="默认值" fixed="固定值"/>
例如声明两个简单元素 name
和 age
:
<xs:element name="name" type="xs:string"/>
<xs:element name="age" type="xs:integer"/><name>Smith</name>
<age>28</age>
4.2、属性 - attribute
attribute 类型是从 annotated 类型扩展派生,拥有 simpleType 子元素和 type、use、default、fixed、form 等属性。
<xs:complexType name="attribute"><xs:complexContent><xs:extension base="xs:annotated"><xs:sequence><xs:element name="simpleType" minOccurs="0" type="xs:localSimpleType"/></xs:sequence><xs:attributeGroup ref="xs:defRef"/><xs:attribute name="type" type="xs:QName"/><xs:attribute name="use" use="optional" default="optional"><xs:simpleType><xs:restriction base="xs:NMTOKEN"><xs:enumeration value="prohibited"/><xs:enumeration value="optional"/><xs:enumeration value="required"/></xs:restriction></xs:simpleType></xs:attribute><xs:attribute name="default" type="xs:string"/><xs:attribute name="fixed" type="xs:string"/><xs:attribute name="form" type="xs:formChoice"/></xs:extension></xs:complexContent>
</xs:complexType>
attribute
元素定义一个属性。
<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>
use
属性
可选。规定如何使用该属性。默认值是optional
可选的。可以设置为下列值:optional
- 属性是可选的prohibited
- 属性不能使用required
- 属性是必需的
form
属性
可选。规定属性的格式。默认值是 包含该属性的元素 的attributeFormDefault
属性的值。可以设置为下列值:qualified
- 指示必须通过命名空间前缀和该属性的本地名称(即无冒号名称,NCName)来限定此属性unqualified
- 指示此属性无须通过命名空间前缀限定,且无须匹配此属性的本地名称 (无须匹配本地名称不太理解是什么意思?)
default
和fixed
属性不能同时出现ref
和name
、form
、type
等属性不能同时出现ref
属性和simpleType
子元素不能同时出现type
属性和simpleType
子元素不能同时出现
例如声明一个 country
属性,限定属性值是大写字母 A 到 Z 中的两个字母:
<xs:attribute name="country"><xs:simpleType><xs:restriction base="xs:string"><xs:pattern value="[A-Z][A-Z]"/></xs:restriction></xs:simpleType>
</xs:attribute>
4.3、限定 12 种 - facet 类型
本部分内容翻译自 W3C Recommendation
Restrictions are used to define acceptable values for XML elements or attributes. Restrictions on XML elements are called facets.
限定(restriction)用于为 XML 元素或者属性定义可接受的值。对 XML 元素的限定被称为 facet (/ˈfæsɪt/,方面)。
在 XMLSchema.xsd 文件中对 facets
元素组的定义如下:
<xs:group name="facets"><xs:choice><xs:element ref="xs:minExclusive"/><xs:element ref="xs:minInclusive"/><xs:element ref="xs:maxExclusive"/><xs:element ref="xs:maxInclusive"/><xs:element ref="xs:totalDigits"/><xs:element ref="xs:fractionDigits"/><xs:element ref="xs:length"/><xs:element ref="xs:minLength"/><xs:element ref="xs:maxLength"/><xs:element ref="xs:enumeration"/><xs:element ref="xs:pattern"/><xs:element ref="xs:whiteSpace"/></xs:choice>
</xs:group>
限定 | 描述 |
---|---|
minExclusive | 定义数值或者日期的下限。所允许的值必需大于此值。等同于左开区间。 |
minInclusive | 定义数值或者日期的下限。所允许的值必需大于或等于此值。等同于左闭区间。 |
maxExclusive | 定义数值或者日期的上限。所允许的值必须小于此值。等同于右开区间。 |
maxInclusive | 定义数值或者日期的上限。所允许的值必须小于或等于此值。等同于右闭区间。 |
totalDigits | 定义所允许的十进制数的精确位数。必须大于0。 |
fractionDigits | 定义所允许的十进制数的最大的小数位数。必须大于或等于0。 |
length | 定义所允许的字符或者列表项的精确数目。必须大于或等于0。 |
minLength | 定义所允许的字符或者列表项的最小数目。必须大于或等于0。 |
maxLength | 定义所允许的字符或者列表项的最大数目。必须大于或等于0。 |
enumeration | 定义可接受值的一个枚举列表。 |
pattern | 定义可接受的字符的正则表达式。 |
whiteSpace | 定义空白字符(换行、回车、空格以及制表符)的处理方式。 |
4.3.1、有序限定 4 种
4.3.1.1、左开区间 - minExclusive 元素
<minExclusive
fixed = boolean : false
id = ID
value = anySimpleType
{any attributes with non-schema namespace . . .}>Content: (annotation?)
</minExclusive>
[Definition]
minExclusive
is the exclusive lower bound
of the value space
for a datatype with the ordered property. The value of minExclusive must be in the value space of the base type or be equal to {value} in {base type definition}.
minExclusive
是具有有序属性的数据类型的值空间的左开区间。minExclusive
的值必须在基本类型的值空间中。
[Example]
The following is the definition of a user-derived
datatype which limits values to integers greater than or equal to 100, using minExclusive
.
如下示例定义了一个从 integer
类型派生的简单类型 more-than-ninety-nine
,通过 minExclusive
限定了大于或等于 100 的整数值。
<simpleType name="more-than-ninety-nine"><restriction base="integer"><minExclusive value="99"/></restriction>
</simpleType>
注:
- 同时定义
minInclusive
和minExclusive
是不合法的 - 同时定义
maxInclusive
和maxExclusive
是不合法的 minExclusive
>=maxInclusive
、minExclusive
>maxExclusive
是不合法的minInclusive
>=maxExclusive
、minInclusive
>maxInclusive
是不合法的
4.3.1.2、左闭区间 - minInclusive 元素
4.3.1.3、右开区间 - maxExclusive 元素
4.3.1.4、右闭区间 - maxInclusive 元素
4.3.2、数值限定 5 种
4.3.2.1、总位数 - totalDigits 元素
<totalDigits
fixed = boolean : false
id = ID
value = positiveInteger
{any attributes with non-schema namespace . . .}>Content: (annotation?)
</totalDigits>
[Definition:] totalDigits controls the maximum number of values in the ·value space· of datatypes ·derived· from decimal, by restricting it to numbers that are expressible as i × 10^-n where i and n are integers such that |i| < 10^totalDigits and 0 <= n <= totalDigits. The value of totalDigits ·must· be a positiveInteger.
totalDigits
通过表示形式 i×10^n 的数字来限制从十进制派生的数据类型的值空间中的最大值,i 和 n 是整数,因此 |i|<10^totalDigets 和 0<=n<=totalDigits。totalDigits
的值必须是正整数。
4.3.2.2、小数位数 - fractionDigits 元素
<fractionDigits
fixed = boolean : false
id = ID
value = nonNegativeInteger
{any attributes with non-schema namespace . . .}>Content: (annotation?)
</fractionDigits>
[Definition]
fractionDigits
controls the size of the minimum difference between values in the value space
of datatypes derived from decimal, by restricting the value space to numbers that are expressible as i × 10^-n where i and n are integers and 0 <= n <= fractionDigits. The value of fractionDigits must be a nonNegativeInteger.
[Example]
The following is the definition of a user-derived
datatype which could be used to represent the magnitude of a person’s body temperature on the Celsius scale. This definition would appear in a schema authored by an “end-user” and shows how to define a datatype by specifying facet values which constrain the range of the base type
.
如下示例定义一个从 decimal
派生的简单类型 celsiusBodyTemp
,表示人的摄氏度体温,totalDigits 的值是 4,小数点也算位数?
<simpleType name='celsiusBodyTemp'><restriction base='decimal'><totalDigits value='4'/><fractionDigits value='1'/><minInclusive value='36.4'/><maxInclusive value='40.5'/></restriction>
</simpleType>
4.3.2.3、长度 - length 元素
4.3.2.4、最小长度 - minLength 元素
<minLength
fixed = boolean : false
id = ID
value = nonNegativeInteger
{any attributes with non-schema namespace . . .}>(annotation?)
</minLength>
4.3.2.5、最大长度 - maxLength 元素
4.3.3、非固定值限定 2 种
4.3.3.1、枚举值限定 - enumeration 元素
4.3.3.2、字符串匹配模式 - pattern 元素
<pattern
id = ID
value = string
{any attributes with non-schema namespace . . .}>Content: (annotation?)
</pattern>
[Definition]
pattern
is a constraint on the value space
of a datatype which is achieved by constraining the lexical space
to literals which match a specific pattern. The value of pattern must be a regular expression
.
pattern
元素是对数据类型的值空间的约束,通过将词汇空间约束为与特定模式匹配的字面量来实现。pattern
的值必须是正则表达式。
[Example]
The following is the definition of a user-derived
datatype which is a better representation of postal codes in the United States, by limiting strings to those which are matched by a specific regular expression
.
如下示例定义了一个从 string
类型派生的简单类型 better-us-zipcode
,用来表示美国的邮政编码,并通过正则表达式限制了字符串的取值范围。
<simpleType name='better-us-zipcode'><restriction base='string'><pattern value='[0-9]{5}(-[0-9]{4})?'/></restriction>
</simpleType>
4.3.4、空白字符限定 1 种
4.3.4.1、空白字符处理 - whiteSpace 元素
<xs:element name="whiteSpace" id="whiteSpace"><xs:annotation><xs:documentation source="http://www.w3.org/TR/xmlschema-2/#element-whiteSpace"/></xs:annotation><xs:complexType><xs:complexContent><xs:restriction base="xs:facet"><xs:sequence><xs:element ref="xs:annotation" minOccurs="0"/></xs:sequence><xs:attribute name="value" use="required"><xs:simpleType><xs:restriction base="xs:NMTOKEN"><xs:enumeration value="preserve"/><xs:enumeration value="replace"/><xs:enumeration value="collapse"/></xs:restriction></xs:simpleType></xs:attribute><xs:anyAttribute namespace="##other" processContents="lax"/></xs:restriction></xs:complexContent></xs:complexType>
</xs:element>
[Definition]
whiteSpace
constrains the value space of types derived from string
such that the various behaviors specified in Attribute Value Normalization in [XML 1.0 (Second Edition)] are realized. The value of whiteSpace must be one of {preserve, replace, collapse}
.
whiteSpace 限制 string 派生类型的值空间,用来规范化属性值,whiteSpace 的 value 属性是必须的,且必须是 preserve, replace, collapse 其中之一。
-
preserve
:XML 处理器不会对空白字符做任何处理
No normalization is done, the value is not changed (this is the behavior required by [XML 1.0 (Second Edition)] for element content). -
replace
:XML 处理器会使用空格替换所有空白字符(制表符、换行以及回车)
All occurrences of #x9 (tab), #xA (line feed) and #xD (carriage return) are replaced with #x20 (space). -
collapse
:XML 处理器会使用空格替换所有空白字符(制表符、换行以及回车),多个连续空格会被缩减为一个空格,开头和结尾的空格会被移除
After the processing implied by replace, contiguous sequences of #x20’s are collapsed to a single #x20, and leading and trailing #x20’s are removed.
例如 XSD 中 token
简单类型的定义:
<xs:simpleType name="token" id="token"><xs:annotation><xs:documentation source="http://www.w3.org/TR/xmlschema-2/#token"/></xs:annotation><xs:restriction base="xs:normalizedString"><xs:whiteSpace value="collapse" id="token.whiteSpace"/></xs:restriction>
</xs:simpleType>
5、XSD 复合类型
complexType
类型定义复合类型。复合类型的元素是 包含其他元素 或 属性 的 XML 元素。
<xs:complexType name="complexType" abstract="true"><xs:complexContent><xs:extension base="xs:annotated"><xs:group ref="xs:complexTypeModel"/><xs:attribute name="name" type="xs:NCName"/><xs:attribute name="mixed" type="xs:boolean" use="optional" default="false"/><xs:attribute name="abstract" type="xs:boolean" use="optional" default="false"/><xs:attribute name="final" type="xs:derivationSet"/><xs:attribute name="block" type="xs:derivationSet"/></xs:extension></xs:complexContent>
</xs:complexType><xs:element name="complexType" type="xs:topLevelComplexType" id="complexType"><xs:annotation><xs:documentation source="http://www.w3.org/TR/xmlschema-1/#element-complexType"/></xs:annotation>
</xs:element>
-
mixed
可选。规定是否允许字符数据出现在该复杂类型的子元素之间。默认值为 false。
如果子元素是simpleContent
元素,则不允许mixed
属性。
如果子元素是complexContent
元素,则mixed
属性可以被complexContent
元素的mixed
属性重写。 -
abstract
可选。规定在实例文档中是否可以直接使用该复合类型,类似 Java 中的 abstract 关键字。如果值为 true,则元素不能直接使用该复合类型,而是必须使用从该复合类型派生的复合类型。默认值为 false。 -
final
可选。防止从该complexType
元素指定的类型派生出新的类型,类似 Java 中的 final 关键字。该值可以包含:#all
- 防止所有派生(扩展和限制)extension
- 防止通过扩展派生restriction
- 防止通过限制派生
-
block
复合类型指示器
Occurrence 指示器 - occurs 属性组
minOccurs 属性
<xs:attribute name="minOccurs"
type="xs:nonNegativeInteger"
use="optional"
default="1"/>
minOccurs
指示器规定某个元素能够出现的最小次数。
maxOccurs 属性
<xs:attribute name="maxOccurs"
type="xs:allNNI"
use="optional"
default="1"/>
maxOccurs
指示器规定某个元素能够出现的最大次数,如果某个元素的出现次数不受限制,使用 maxOccurs="unbounded"
。
例如规定 class
元素可以有多个 student
子元素而只能有 1-2 个 teacher
子元素:
<xs:element name="class"><xs:complexType><xs:sequence><xs:element name="student" type="xs:string"maxOccurs="unbounded"/><xs:element name="teacher" type="xs:string"minOccurs="1" maxOccurs="2"/></xs:sequence></xs:complexType>
</xs:element>
Order 指示器 - explicitGroup 复合类型
choice 元素和 sequence 元素
choice
元素规定仅允许 <xs:choice>
声明的元素之一出现。
sequence
元素规定 <xs:sequence>
声明的元素以指定的顺序出现,每个子元素可以出现 0 次到任意次数。
<xs:element name="choice" type="xs:explicitGroup" id="choice"><xs:annotation><xs:documentation source="http://www.w3.org/TR/xmlschema-1/#element-choice"/></xs:annotation>
</xs:element><xs:element name="sequence" type="xs:explicitGroup" id="sequence"><xs:annotation><xs:documentation source="http://www.w3.org/TR/xmlschema-1/#element-sequence"/></xs:annotation>
</xs:element>
choice 和 sequence 元素是 explicitGroup 类型。
- explicitGroup 类型不支持 name 和 ref 属性
- explicitGroup 类型引用了 nestedParticle 元素组,nestedParticle 元素组提供 element、group、choice、sequence、any 等元素其中之一
- explicitGroup 类型继承 group 类型
- group 类型引用了 defRef 和 occurs 属性组,defRef 属性组提供 name 和 ref 属性,occurs 属性组提供可选的 minOccurs 和 maxOccurs 属性
- group 类型继承 annotated 类型
- annotated 类型提供了 annotation 子元素和 id 属性
综上所述 choice 和 sequence 元素的定义如下:
<choice
id=ID
minOccurs=nonNegativeInteger
maxOccurs=nonNegativeInteger|unbounded
any attributes
>(annotation?,(element|group|choice|sequence|any)*)
</choice><sequence
id=ID
maxOccurs=nonNegativeInteger|unbounded
minOccurs=nonNegativeInteger
any attributes
>(annotation?,(element|group|choice|sequence|any)*)
</sequence>
all 元素
all
元素规定子元素能够以任意顺序出现,每个子元素可以出现零次或一次。
<xs:complexType name="all"><xs:complexContent><xs:restriction base="xs:explicitGroup"><xs:group ref="xs:allModel"/><xs:attribute name="minOccurs" use="optional" default="1"/><xs:attribute name="maxOccurs" use="optional" default="1"/><xs:anyAttribute namespace="##other" processContents="lax"/></xs:restriction></xs:complexContent>
</xs:complexType><xs:element name="all" id="all" type="xs:all"><xs:annotation><xs:documentation source="http://www.w3.org/TR/xmlschema-1/#element-all"/></xs:annotation>
</xs:element>
all 元素是 all 类型。
- all 类型继承 explicitGroup 类型
- all 类型引用了 allModel 元素组
- all 类型提供可选的 minOccurs 和 maxOccurs 属性
综上所述 all 元素的定义如下:
<all
id=ID
minOccurs=0|1
maxOccurs=1
any attributes
>(annotation?,element*)
</all>
例如规定 person
元素中 firstname
和 lastname
子元素能够以任意顺序出现零次或一次:
<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>
Group 指示器
元素组 - realGroup 复合类型
group
元素用于对元素声明进行组合,这样这些声明就能够以组合的形式合并到复合类型中。
<group
id=ID
name=NCName
ref=QName
minOccurs=nonNegativeInteger
maxOccurs=nonNegativeInteger|unbounded
any attributes
>(annotation?,(all|choice|sequence)?)
</group>
例如声明一个元素组 attrDecls
,然后声明一个复合类型 attributeGroup
并引用 attrDecls
元素组:
<xs:group name="attrDecls"><xs:sequence><xs:choice minOccurs="0" maxOccurs="unbounded"><xs:element name="attribute" type="xs:attribute"/><xs:element name="attributeGroup" type="xs:attributeGroupRef"/></xs:choice><xs:element ref="xs:anyAttribute" minOccurs="0"/></xs:sequence>
</xs:group><xs:complexType name="attributeGroup" abstract="true"><xs:complexContent><xs:extension base="xs:annotated"><xs:group ref="xs:attrDecls"/><xs:attributeGroup ref="xs:defRef"/></xs:extension></xs:complexContent>
</xs:complexType>
属性组 - attributeGroup 复合类型
attributeGroup 类型是抽象(abstract=“true”)类型,从 annotated 类型扩展派生,新增了 attrDecls 元素组和 defRef 属性组。
<xs:complexType name="attributeGroup" abstract="true"><xs:complexContent><xs:extension base="xs:annotated"><xs:group ref="xs:attrDecls"/><xs:attributeGroup ref="xs:defRef"/></xs:extension></xs:complexContent>
</xs:complexType>
例如声明一个属性组 defRef
,包含 name 和 ref 属性,然后在复合类型 customer 中引用:
<xs:attributeGroup name="defRef"><xs:annotation><xs:documentation>for element, group and attributeGroup, which both define and reference</xs:documentation></xs:annotation><xs:attribute name="name" type="xs:NCName"/><xs:attribute name="ref" type="xs:QName"/>
</xs:attributeGroup>
attributeGroup
元素用于对属性声明进行组合,这样这些声明就能够以组合的形式合并到复合类型中。
<attributeGroup
id=ID
name=NCName
ref=QName
any attributes
>(annotation?),((attribute|attributeGroup)*,anyAttribute?))
</attributeGroup>
元素类型 - element 类型
<xs:complexType name="element" abstract="true"><xs:annotation><xs:documentation>The element element can be used either at the top level to define an element-type binding globally, or within a content model to either reference a globally-defined element or type or declare an element-type binding locally. The ref form is not allowed at the top level.</xs:documentation></xs:annotation><xs:complexContent><xs:extension base="xs:annotated"><xs:sequence><xs:choice minOccurs="0"><xs:element name="simpleType" type="xs:localSimpleType"/><xs:element name="complexType" type="xs:localComplexType"/></xs:choice><xs:group ref="xs:identityConstraint" minOccurs="0" maxOccurs="unbounded"/></xs:sequence><xs:attributeGroup ref="xs:defRef"/><xs:attribute name="type" type="xs:QName"/><xs:attribute name="substitutionGroup" type="xs:QName"/><xs:attributeGroup ref="xs:occurs"/><xs:attribute name="default" type="xs:string"/><xs:attribute name="fixed" type="xs:string"/><xs:attribute name="nillable" type="xs:boolean" use="optional" default="false"/><xs:attribute name="abstract" type="xs:boolean" use="optional" default="false"/><xs:attribute name="final" type="xs:derivationSet"/><xs:attribute name="block" type="xs:blockSet"/><xs:attribute name="form" type="xs:formChoice"/></xs:extension></xs:complexContent>
</xs:complexType>
复合元素
复合元素指包含其他元素或属性的 XML 元素。
<xs:element name="employee" type="fullpersoninfo"/><xs:complexType name="personinfo"><xs:sequence><xs:element name="firstname" type="xs:string"/><xs:element name="lastname" type="xs:string"/></xs:sequence>
</xs:complexType><xs:complexType name="fullpersoninfo"><xs:complexContent><xs:extension base="personinfo"><xs:sequence><xs:element name="address" type="xs:string"/><xs:element name="city" type="xs:string"/><xs:element name="country" type="xs:string"/></xs:sequence></xs:extension></xs:complexContent>
</xs:complexType>
通配符类型 - wildcard 复合类型
<xs:complexType name="wildcard"><xs:complexContent><xs:extension base="xs:annotated"><xs:attribute name="namespace" type="xs:namespaceList" use="optional" default="##any"/><xs:attribute name="processContents" use="optional" default="strict"><xs:simpleType><xs:restriction base="xs:NMTOKEN"><xs:enumeration value="skip"/><xs:enumeration value="lax"/><xs:enumeration value="strict"/></xs:restriction></xs:simpleType></xs:attribute></xs:extension></xs:complexContent>
</xs:complexType>
-
namespace
可选。规定包含可以使用的元素的命名空间。如果没有指定命名空间,则默认值是##any
。如果指定命名空间,则取值必须是以下之一:##any
- 来自任何命名空间的元素都可以出现##other
- 来自该元素的父元素的目标命名空间之外的任何命名空间的元素都可以出现##local
- 未由命名空间限定的元素可以出现##targetNamespace
- 来自包含该元素的父元素的目标命名空间的元素可以出现{URI references of namespaces, ##targetNamespace, ##local}
的列表 - 来自通过空格分隔的命名空间列表的元素可以出现。 该列表可以包含以下内容: 命名空间##targetNamespace
和##local
的 URI 引用。
-
processContents
可选。一个指示符,指示应用程序或 XML 处理器应如何根据由该any
元素指定的元素处理 XML 文档的验证。 如果没有指定processContents
属性,则默认为strict
。如果指定了processContents
,则取值必须是以下之一:strict
- XML 处理器必须获得所需命名空间的架构,并且必须验证来自这些命名空间的所有元素lax
- 与strict
相同;但是,即使不能获取该架构,也不会发生任何错误skip
- XML 处理器不尝试验证来自指定命名空间的所有元素
任何元素 - any 元素
any
元素是复合类型元素,类型是从 wildcard 类型扩展的派生类型。
wildcard 类型的 namespace 属性默认值是 ##any
,使来自指定命名空间的任何元素可以显示在包含 sequence
或 choice
元素中。
该元素使创作者可以通过未被 schema 规定的元素来扩展 XML 文档。
<xs:element name="any" id="any"><xs:annotation><xs:documentation source="http://www.w3.org/TR/xmlschema-1/#element-any"/></xs:annotation><xs:complexType><xs:complexContent><xs:extension base="xs:wildcard"><xs:attributeGroup ref="xs:occurs"/></xs:extension></xs:complexContent></xs:complexType>
</xs:element><any
id=ID
maxOccurs=nonNegativeInteger|unbounded
minOccurs=nonNegativeInteger
namespace=namespace
processContents=lax|skip|strict
any attributes
>(annotation?)
</any>
任何属性 - anyAttribute 元素
<xs:element name="anyAttribute" type="xs:wildcard" id="anyAttribute"><xs:annotation><xs:documentation source="http://www.w3.org/TR/xmlschema-1/#element-anyAttribute"/></xs:annotation>
</xs:element>
anyAttribute
元素使创作者可以通过未被 schema 规定的属性来扩展 XML 文档。
注释 - annotation 元素
annotation
元素是一个顶层元素,规定 schema 的注释。
<xs:element name="annotation" id="annotation"><xs:annotation><xs:documentation source="http://www.w3.org/TR/xmlschema-1/#element-annotation"/></xs:annotation><xs:complexType><xs:complexContent><xs:extension base="xs:openAttrs"><xs:choice minOccurs="0" maxOccurs="unbounded"><xs:element ref="xs:appinfo"/><xs:element ref="xs:documentation"/></xs:choice><xs:attribute name="id" type="xs:ID"/></xs:extension></xs:complexContent></xs:complexType>
</xs:element><xs:element name="appinfo" id="appinfo"><xs:annotation><xs:documentation source="http://www.w3.org/TR/xmlschema-1/#element-appinfo"/></xs:annotation><xs:complexType mixed="true"><xs:sequence minOccurs="0" maxOccurs="unbounded"><xs:any processContents="lax"/></xs:sequence><xs:attribute name="source" type="xs:anyURI"/><xs:anyAttribute namespace="##other" processContents="lax"/></xs:complexType>
</xs:element><xs:element name="documentation" id="documentation"><xs:annotation><xs:documentation source="http://www.w3.org/TR/xmlschema-1/#element-documentation"/></xs:annotation><xs:complexType mixed="true"><xs:sequence minOccurs="0" maxOccurs="unbounded"><xs:any processContents="lax"/></xs:sequence><xs:attribute name="source" type="xs:anyURI"/><xs:attribute ref="xml:lang"/><xs:anyAttribute namespace="##other" processContents="lax"/>
</xs:complexType>
</xs:element>
<annotation
id=ID
any attributes
>(appinfo|documentation)*
</annotation>
可以包含 appinfo 元素(由应用程序使用的信息)和 documentation 元素(由用户读取或使用的注释或文本)。
appInfo 元素规定 annotation 元素中应用程序要使用的信息。该元素必须位于 annotation 中。
注释:应用程序使用在 appinfo 元素内提供的信息处理指令。
<appInfo
source=anyURL
>
Any well-formed XML content
</appInfo>
source 可选。一个 URI 引用,规定应用程序信息的来源。
documentation 元素在 schema 中输入文本注释。该元素必须位于 annotation 元素内。
source 可选。规定应用程序信息的来源。
xml:lang 可选。规定内容中使用的语言。
<xs:annotation><xs:appInfo>W3School Note</xs:appInfo><xs:documentation xml:lang="en">This Schema defines a W3School note!</xs:documentation>
</xs:annotation>
相关文章:

XML 学习笔记 7:XSD
本文章内容参考自: W3school XSD 教程 Extensible Markup Language (XML) 1.0 (Second Edition) XML Schema 2001 XML Schema Part 2: Datatypes Second Edition 文章目录 1、XSD 是什么2、XSD 内置数据类型 - built-in datatypes2.1、基本数据类型 19 种2.1.1、基本…...
neo4j图数据库基础操作命令(CQL语法)
天行健,君子以自强不息;地势坤,君子以厚德载物。 每个人都有惰性,但不断学习是好好生活的根本,共勉! 文章均为学习整理笔记,分享记录为主,如有错误请指正,共同学习进步。…...

vscode无法连接远程服务器的可能原因:远程服务器磁盘爆了
vscode输入密码后一直等待,无法进入远程服务器终端: 同时Remote-SSH输出包含以下内容 在日志中的以下几个部分: [17:15:05.529] > wget download failed 这表明VS Code尝试在远程服务器上下载VS Code服务器时失败了。> Cannot write…...

SSL 证书过期巡检脚本 (Python 版)
哈喽大家好,我是咸鱼 之前写了个 shell 版本的 SSL 证书过期巡检脚本 (文章:《SSL 证书过期巡检脚本》),后台反响还是很不错的 那么今天咸鱼给大家介绍一下 python 版本的 SSL 证书过期巡检脚本 (完整代码…...

从0到1自学网络安全(黑客)【附学习路线图+配套搭建资源】
前言 网络安全产业就像一个江湖,各色人等聚集。相对于欧美国家基础扎实(懂加密、会防护、能挖洞、擅工程)的众多名门正派,我国的人才更多的属于旁门左道(很多白帽子可能会不服气),因此在未来的…...

Michael.W基于Foundry精读Openzeppelin第20期——EnumerableMap.sol
0. 版本 [openzeppelin]:v4.8.3,[forge-std]:v1.5.6 0.1 EnumerableMap.sol Github: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.8.3/contracts/utils/structs/EnumerableMap.sol EnumerableMap库提供了Bytes32ToB…...
深入探索二叉树:应用、计算和遍历
当涉及到二叉树的计算问题时,我们可以进一步介绍如何计算叶子节点数、树的宽度和叶子的深度,并解释三种常见的二叉树遍历方式:先序遍历、中序遍历和后序遍历。 1. 计算叶子节点数 叶子节点是指没有子节点的节点,也就是树中的末端…...
关于 1 + 1 = 2 的证明
1 1 2 首先是皮亚诺的自然数公理 意大利数学家皮亚诺提出的关于自然数的 5 5 5 条公理如下(定义 S ( x ) S(x) S(x) 为自然数 x x x 的后继): 0 0 0 是自然数每一个自然数 n n n 都有一个自然数后继记为 S ( n ) S(n) S(n) 0 0 0 不是…...

【C++】——内存管理
目录 回忆C语言内存管理C内存管理方式new deleteoperator new与operator delete函数new和delete的实现原理定位new表达式(placement-new)malloc/free和new/delete的区别 回忆C语言内存管理 void Test() {int* p1 (int*)malloc(sizeof(int));free(p1);int* p2 (int*)calloc(4…...

Jmeter录制HTTPS脚本
Jmeter录制HTTPS脚本 文章目录 添加“HTTP代理服务器”设置浏览器代理证书导入存在问题 添加“HTTP代理服务器” 设置浏览器代理 保持端口一致 证书导入 点击一下启动让jmeter自动生成证书,放在bin目录下: 打开jmeter的SSL管理器选择刚刚生成的证书&…...
Linux 的Centos 7 安装 启动 Google Chrome
我之所以在Centos上安装Chrome主要是为了让Web自动化测试工具可以启动Chrome,协助我做一些工作。 参考:centos7 google-chrome的安装与启动 - 简书 1.安装chrome逻辑 1. 下载安装包 2. 安装 3. 启动 》这就是在window上的逻辑,只是用命令行…...

DNS WEB HTTP
DNS与域名 网络是基于 TCP/IP 协议进行通信和连接的。 每一台主机都有唯一的标识,用于区别在网络上成千上万个用户和计算机。即固定的IP地址(32位二进制数转换成为十进制数——点分十进制)。每一个与网络相连接的计算机和服务器都被指派一个…...

微信小程序animation动画,微信小程序animation动画无限循环播放
需求是酱紫的: 页面顶部的喇叭通知,内容不固定,宽度不固定,就是做走马灯(轮播)效果,从左到右的走马灯(轮播),每播放一遍暂停 1500ms ~ 2000ms 刚…...

node.js
什么是Node.js Node.js 是一个免费的、开源的、跨平台的 JavaScript 运行时环境,使开发者可以搭建服务器端的JavaScript应用程序 概念: 使用Node.js编写后端程序 // 支持前端工程化 后端程序:提供接口和数据 ,网页资源 前端工程化:对代码压缩&…...

【微信小程序创作之路】- 小程序远程数据请求、获取个人信息
【微信小程序创作之路】- 小程序远程数据请求、获取个人信息 第七章 小程序远程数据请求、获取个人信息 文章目录 【微信小程序创作之路】- 小程序远程数据请求、获取个人信息前言一、远程数据请求1.本地环境2.正式域名 二、获取用户个人信息1.展示当前用户的身份信息2.获取用…...

XML基础知识讲解
文章目录 1. xml简介2. xml快速入门3. xml的元素(标签)定义4. xml标签的命名规范5. xml的属性定义和注释6. 转义字符7. CDATA区8. xml的处理指令9. xml的约束 1. xml简介 XML(eXtensible Markup Language)是一种用于描述数据的标记语。 它以纯文本的方…...

(十二)大数据实战——hadoop集群之HDFS高可用自动故障转移
前言 本节内容主要介绍一下hadoop集群下实现HDFS高可用的自动故障转移,HDFS高可用的自动故障转移主要通过zookeeper实现故障的监控和主节点的切换。自动故障转移为 HDFS 部署增加了两个新组件:ZooKeeper 和 ZKFailoverController (ZKFC&…...
Ubuntu下载deb包及其依赖包
一、简介 有时我们需要在离线环境使用提前准备好的deb包,然后只需要在新机器使用dpkg -i安装即可。 二、命令 apt-get download $(apt-rdepends (需要下载的包,可以有多个) | grep -v "^ " | sed s/debconf-2.0/debco…...
Ubuntu中解/压缩命令
一、zip文件 #解压 unzip filename.zip #压缩 zip filename.zip dirname # 递归处理,将指定目录下的所有文件和子目录一并压缩 zip -r filename.zip dirname 二、tar文件 # 解压 tar xvf FileName.tar # 压缩,将DirName和其下所有文件(夹)打包非压…...

剑指 Offer 12. 矩阵中的路径(回溯 DFS)
文章目录 题目描述思路分析完整代码 题目描述 给定一个 m x n 二维字符网格 board 和一个字符串单词 word 。如果 word 存在于网格中,返回 true ;否则,返回 false 。 单词必须按照字母顺序,通过相邻的单元格内的字母构成ÿ…...
SkyWalking 10.2.0 SWCK 配置过程
SkyWalking 10.2.0 & SWCK 配置过程 skywalking oap-server & ui 使用Docker安装在K8S集群以外,K8S集群中的微服务使用initContainer按命名空间将skywalking-java-agent注入到业务容器中。 SWCK有整套的解决方案,全安装在K8S群集中。 具体可参…...

树莓派超全系列教程文档--(61)树莓派摄像头高级使用方法
树莓派摄像头高级使用方法 配置通过调谐文件来调整相机行为 使用多个摄像头安装 libcam 和 rpicam-apps依赖关系开发包 文章来源: http://raspberry.dns8844.cn/documentation 原文网址 配置 大多数用例自动工作,无需更改相机配置。但是,一…...

【JavaEE】-- HTTP
1. HTTP是什么? HTTP(全称为"超文本传输协议")是一种应用非常广泛的应用层协议,HTTP是基于TCP协议的一种应用层协议。 应用层协议:是计算机网络协议栈中最高层的协议,它定义了运行在不同主机上…...

边缘计算医疗风险自查APP开发方案
核心目标:在便携设备(智能手表/家用检测仪)部署轻量化疾病预测模型,实现低延迟、隐私安全的实时健康风险评估。 一、技术架构设计 #mermaid-svg-iuNaeeLK2YoFKfao {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg…...

vscode(仍待补充)
写于2025 6.9 主包将加入vscode这个更权威的圈子 vscode的基本使用 侧边栏 vscode还能连接ssh? debug时使用的launch文件 1.task.json {"tasks": [{"type": "cppbuild","label": "C/C: gcc.exe 生成活动文件"…...

Vue2 第一节_Vue2上手_插值表达式{{}}_访问数据和修改数据_Vue开发者工具
文章目录 1.Vue2上手-如何创建一个Vue实例,进行初始化渲染2. 插值表达式{{}}3. 访问数据和修改数据4. vue响应式5. Vue开发者工具--方便调试 1.Vue2上手-如何创建一个Vue实例,进行初始化渲染 准备容器引包创建Vue实例 new Vue()指定配置项 ->渲染数据 准备一个容器,例如: …...
OkHttp 中实现断点续传 demo
在 OkHttp 中实现断点续传主要通过以下步骤完成,核心是利用 HTTP 协议的 Range 请求头指定下载范围: 实现原理 Range 请求头:向服务器请求文件的特定字节范围(如 Range: bytes1024-) 本地文件记录:保存已…...
Linux云原生安全:零信任架构与机密计算
Linux云原生安全:零信任架构与机密计算 构建坚不可摧的云原生防御体系 引言:云原生安全的范式革命 随着云原生技术的普及,安全边界正在从传统的网络边界向工作负载内部转移。Gartner预测,到2025年,零信任架构将成为超…...
Axios请求超时重发机制
Axios 超时重新请求实现方案 在 Axios 中实现超时重新请求可以通过以下几种方式: 1. 使用拦截器实现自动重试 import axios from axios;// 创建axios实例 const instance axios.create();// 设置超时时间 instance.defaults.timeout 5000;// 最大重试次数 cons…...

C# 求圆面积的程序(Program to find area of a circle)
给定半径r,求圆的面积。圆的面积应精确到小数点后5位。 例子: 输入:r 5 输出:78.53982 解释:由于面积 PI * r * r 3.14159265358979323846 * 5 * 5 78.53982,因为我们只保留小数点后 5 位数字。 输…...