DTD和schema语法的区别(二)
2008-10-19 20:01
281 查看
定义元素属性 ;/o026D]P
DTD定义元素的语法格式是<!ATTLIST 元素名 属性名 属性类型 元素对属性的要求 默认值>,其中属性类型指的是“DTD和schema语法的区别(一)”第2点提到的那五个类型,元素对属性的要求则有三种,分别是#REQUIRED(必需),#IMPLIED(该属性是可有可无的),#FIXED(固定值)。至于最后一项默认值,如果选择了#FIXED作为元素对属性的约束,则必须要指定,否则可有可无。 Z6KjL2
Schema中使用xsd:attribute元素定义属性,有两种方法来定义,一是直接将属性作为complexType的子元素定义,即<xsd:attribute name=”属性名” type=”属性类型”>,如下例子: K[#Qq+M
例子一:<xsd:attribute name="id" type="xsd:ID"/> uGN#9
例子二:<xsd:attribute name="娱乐程度" type="娱乐程度"/> uV:bH ?6
<xsd:simpleType name="娱乐程度"> @[m3/("h
<xsd:restriction base="xsd:string"> ;'VQmN*
<xsd:enumeration value="高"/> e;ZM_L
<xsd:enumeration value="中"/> hk)Dy"df_
<xsd:enumeration value="低"/> (%j;I(
</xsd:restriction> <|Y&p^Bg
</xsd:simpleType> +Ji$@9
二是先把属性独立定义好,然后再在complexType中使用<xsd:attribute ref=”已存在的属性”>,如下例子: 3.+q_C<f
<xsd:complexType name="bewrite"> ;sz9S3ss
<xsd:sequence> S!y>)3=j
<xsd:element ref="归类"/> :<Uc<ru8
<xsd:element ref="举办地点"/> LC^~yY
</xsd:sequence> 1tqh =r*
<xsd:attribute ref="name"/> 8).L:2WV/|
</xsd:complexType> wSK]lvb
<xsd:attribute name="name" type="xsd:string"/> Kvy# s.P
2'24""d^
另:schema还可以定义属性组,属性组就是将多个属性捆绑在一起,用的时候可以在一起使用,定义属性组使用xsd:attributeGroup元素,如下例子所示: {~[- 7n
<xsd:complexType name="bewrite"> 031G[}B~w
<xsd:sequence> #cW!ir<`9[
<xsd:element ref="归类"/> BX&kdEr
<xsd:element ref="举办地点"/> }U5}i 1Q
<xsd:element ref="门票价格"/> yzy<iax"w
</xsd:sequence> z'w~U;IY
<xsd:attributeGroup ref="id_type"/> 7{5l,lWV31
</xsd:complexType> V :Zg v
6=?u Yo
<xsd:attributeGroup name="id_type"> /id|=.z%
<xsd:attribute ref="id" use="required"/> F_ Ap L7
<xsd:attribute ref="娱乐程度" use="required"/> _Rf#&<fV
</xsd:attributeGroup> 4~?fzI-93
{H`xS@!
<xsd:attribute name="id" type="xsd:ID"/> 3XHN|m|(
<xsd:attribute name="娱乐程度" type="娱乐程度"/> X.VS|;?
相关文章推荐
- DTD和schema语法的区别(一)
- 黑马训练营 -----XML语法与DTD,Schema约束
- day04 面试题Schema约束与DTD约束的区别
- Schema 和DTD区别
- XML DTD跟SCHEMA约束 语法了解
- Schema和DTD的区别
- Schema和DTD的区别,验证XLM数据合法性
- Schema和DTD的区别(2)
- Schema和DTD的区别
- Schema 和DTD区别
- Schema和DTD的区别
- Schema和DTD的区别
- DTD 与 Schema的简单区别
- dtd与schema的区别&XML文件解析常用方式
- xml语法、DTD约束xml、Schema约束xml、DOM解析xml
- DTD和XSchema的区别
- Schema和DTD的区别
- XML中Schema和DTD的区别
- xml编写中的DTD约束与schema约束中的语法
- Schema和DTD的区别