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

被折叠的 条评论
为什么被折叠?



