XSD入门--part3

XSD属性

更多的时候我们碰到的元素会是如下所示:

<name id="xxx" value="xxx"/>

该元素会拥有多个属性,此时我们该定义属性的声明:

<xs:attribute name="属性名称" type="数据类型">

其中常用的数据类型同上一节的常用类型。

举个栗子:

<name code="CH">张三</name>

对应的属性定义:

<xs:attribute name="code" type="xs:string"/>

属性同样拥有指定的默认值或固定值,在此不再详细阐述,直接上栗子:

缺省值为“CH”:

<xs:attribute name="code" type="xs:string" default="CH"/>

固定值为“CH”:

<xs:attribute name="code" type="xs:string" fixed="CH"/>

在缺省时,属性是可选的。如果需要属性为必选,需要加入“use”属性:

<xs:attribute name="code" type="xs:string" use="required"/>

猜你喜欢

转载自meros-z.iteye.com/blog/2290230