XML Scheme备忘

XML Scheme的职责与Xml DTD一样,都是用来定义Xml文件标准的。Xml Scheme是基于xml格式的,这点与Xml Dtd不同。

如何定义节点?

定义节点的语法为:<element name="元素名" type="元素类型"/>

这里的类型可以分为:自定义的简单型(SimpleType)和自定义的复杂型(ComplexType)及系统自带的类型。

如何定义含子节点的节点?

定义语法为:

<element name="rootnode"> <complextype> <sequence> <element name="firstchildnode1" type="某类型"/> <element name="firstchildnode2" type="某类型"/> <element name="firstchildnode3" type="某类型"/> <element name="firstchildnode4" type="某类型"/> </sequence> </complextype> </element>

该scheme对应的xml格式为:

<rootnode> <firstchildnode1/> <firstchildnode2/> <firstchildnode3/> <firstchildnode4/> </rootnode>

如何定义含属性的节点?

<element name="node"> <complextype> <attribute name='attribute1' type="某类型"/> <attribute name='attribute1' type="某类型"/> <attribute name='attribute1' type="某类型"/> </complextype> </element>

该Scheme对应的xml文件

<node attribute1="" attribute2="" attribute3=""/>

如何定义包含属性和子节点的节点?

定义语法为:

<element name="rootnode"> <complextype> <sequence> <element name="firstchildnode1" type="某类型"/> <element name="firstchildnode2" type="某类型"/> <element name="firstchildnode3" type="某类型"/> </sequence> <attribute name="attribute1" type="某类型"/> </complextype> </element>

对应的xml文件为:

<rootnode attribute1=""> <firstchildnode1/> <firstchildnode2/> <firstchildnode3/> </rootnode>

如何定义自己的类型?

在Scheme中,我们可以自定义SimpleType和ComplexType。我们可以将自己定义的类型,指派到相应的节点上。

自定义SimpleType:

<SimpleType name="hello"> <Restriction base="xs:string"> <MinInclude value="10"/> <MaxInclude value="20"/> </Restriction> </SimpleType>

我们定义了hello类型,它是从系统自带的string类型派生的。并且hello类型的字符串长度只能在10~20个字符之间。

自定义ComplexType:

/还不是很明白/

一些让你的Scheme文件更灵活的定义语法:

<sequence>: 包含在该标记里面的子节点必须按定义的顺序出现

<complextype> <sequence> <element name="1" type="**"/> <element name="2" type="**"/> <element name="3" type="**"/> </sequence> </complextype>

<choice>:包含在该标记里面的子节点只能出现一个

<all>:包含在该标记里面的子节点必须全部出现,不必按顺序

<list>:列表类型,用来扩展简单类型的标记

<simpletype> <list> <restriction base="xs:token"> <enumeration value="book"/> <enumeration value="book2"/> <enumeration value="book"3/> </restriction> </list> </simpletype>

<union>:用来扩展简单类型的标记,让元素<root></root>中的值类型可以是多样的

<simpletype> <union> <restriction base="xs:token"> <enumeration value="book"/> <enumeration value="book2"/> <enumeration value="book"3/> </restriction> <restriction base="xs:integer"> <MinInclude value="1"/> <MinInclude value="2"/> </restriction> </union> </simpletype>

mixed属性:用在<complextype>标记上的,让ComplexType类型不但能有子节点,自己也能有文本内容

minOccurs属性:最小出现次数 用在 <element>标记上

maxOccurs属性:最大出现次数 用在 <element>标记上

default属性:用在 <element>,<attribute>标记上

fix属性:用在 <element>,<attribute>标记上

ref属性:用在 <element>标记上 引用在其他地方定义的<element>元素

substitutionGroup属性:用在 <element>标记上

use属性:用在<attribute>标记上 用来设置该属性 是否可选(optional),必须(required),禁止(prohibited)

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值