加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

XMLSchema学习总结

发布时间:2020-12-16 05:31:58 所属栏目:百科 来源:网络整理
导读:XML Schema的总结 一,什么是XML Schema? Xml Schema是对XML数据结构的描述,可以通过XML Schema来定义 XML 文档的合法构建模块,可以用于检测元数据是否合法。 · 比如:date type="date"2004-03-11/date,可确保对内容一致的理解,这是因为 XML 的数据类

XML Schema的总结

一,什么是XML Schema?

Xml Schema是对XML数据结构的描述,可以通过XML Schema来定义 XML 文档的合法构建模块,可以用于检测元数据是否合法。

· 比如:<date type="date">2004-03-11</date>,可确保对内容一致的理解,这是因为 XML 的数据类型 "date" 要求的格式是 "YYYY-MM-DD"

二,XML Schema可以定义以下内容。

· 定义可出现在文档中的元素

· 定义可出现在文档中的属性

· 定义哪个元素是子元素

· 定义子元素的次序

· 定义子元素的数目

· 定义元素是否为空,或者是否可包含文本

· 定义元素和属性的数据类型

· 定义元素和属性的默认值以及固定值

三,关于Xml Schema的用法。

1,定义简易元素的语法:

<xs:element name="age" type="xs:interger"/>

1.1 对元素值的限定:

例如:

<xs:element name=”age>

<xs:simpletype>

<xs:restriction base=xs:integer>

< xs:minInclusive value=”0”>

<xs:maxInclusive value =”120”>

 <xs:restriction>

</xs:simpletype>

</xs:element>

2,定义属性的语法:

<xs:attribute name="xxx" type="yyy"/>

3, 什么是复杂元素:

复合元素指包含其他元素及/或属性的 XML 元素。

复合元素分为四类:

· 空元素

· 包含其他元素的元素

· 仅包含文本的元素

· 包含元素和文本的元素

1,空元素:

Xml <product pid="1345"/>

2,仅包含其他元素:

<employ>

<firstname>john</firstname>

<lastname> smith</lastname>

</employ>

对应的xml schema描述:

<xs:element name="employee">

<xs:complexType>

<xs:sequence>

<xs:element name="firstname" type="xs:string"/>

<xs:element name="lastname" type="xs:string"/>

</xs:sequence>

</xs:complexType>

</xs:element>

3,含有文本和属性的要素:

XML: <shoesize country="france">35</shoesize>

对应的XmlShema:

<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>

4,含有混合内容的复合类型

XML:

<letter>

Dear Mr.<name>John Smith</name>.

Your order <orderid>1032</orderid>

will be shipped on <shipdate>2001-07-13</shipdate>.

</letter>

XMLSchema:

<xs:element name="letter">

<xs:complexType mixed="true">

<xs:sequence>

<xs:element name="name" type="xs:string"/>

<xs:element name="orderid" type="xs:positiveInteger"/>

<xs:element name="shipdate" type="xs:date"/>

</xs:sequence>

</xs:complexType>

</xs:element>

最后,XMLSchema有很多数据类型:1String 2 Date 3Numeric Data 4 Boolean 5 Binary 6 AnyURI。对数值的约束有以下内容: enumeration fractionDigits maxExclusive maxInclusive minExclusive minInclusive pattern totalDigits whiteSpace

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读