W3C Schema复杂类型一

W3C Schema复杂类型一

我准备在复杂类型里添加一个枚举型的值,但是一直失败

        <xs:complexType name = "StaffType">
            <xs:simpleContent>
                <xs:extension base="xs:string">
                    <xs:enumeration value="小明"/>
                    <xs:enumeration value="小红"/>
                    <xs:enumeration value="张三"/>
                    <xs:enumeration value="李四"/>
                    <xs:enumeration value="王五"/>
                    <xs:enumeration value="赵六"/>
                    <xs:attribute name="编号" use="required" type="StaffIDType"/>
                </xs:extension>
            </xs:simpleContent>             
        </xs:complexType>

错误信息如下:

File C:\Users\Gigabyte\Desktop\1.xsd is not valid.

Element is not allowed under element .
Reason: The following elements are expected at this location (see below)




Error location: xs:schema / xs:complexType / xs:simpleContent / xs:extension / xs:enumeration
Details
cvc-model-group: Element unexpected by type ‘xs:simpleExtensionType’ of element .
cvc-elt.5.2.1: The element is not valid with respect to the actual type definition ‘xs:simpleExtensionType’.

原因出在,在extension元素里面只能定义以下

    <xs:annotation>
    <xs:attribute>
    <xs:attributeGroup>
    <xs:anyAttribute>

四个元素

很明显,我们第一段代码是错误的。那怎么解决?

我们把枚举类型的值写到另外一个simpleType里面,然后在complexType的base里选择这个Type。

注意:base指的是填在标签里面的值。

        <xs:complexType name = "StaffType">
            <xs:simpleContent>
                <xs:extension base="StaffNameType">
                    <xs:attribute name="编号" use="required" type="StaffIDType"/>
                </xs:extension>
            </xs:simpleContent>                         
        </xs:complexType>

        <xs:simpleType name="StaffNameType">
                <xs:restriction base="xs:string">
                    <xs:enumeration value="小明"/>
                    <xs:enumeration value="小红"/>
                    <xs:enumeration value="张三"/>
                    <xs:enumeration value="李四"/>
                    <xs:enumeration value="王五"/>
                    <xs:enumeration value="赵六"/>
                </xs:restriction>
        </xs:simpleType>

如果不太理解里面的标签意思,可以参考我的上一篇文章。
http://blog.csdn.net/cg_amaz1ng/article/details/70246988 《XML Schema(W3C)数据类型》

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值