带有枚举和联合的xml简单类型

前端之家收集整理的这篇文章主要介绍了带有枚举和联合的xml简单类型前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_404_1@
解析以下xml架构会产生此错误

element属性:Schemas解析器错误属性decl. ‘current-state’,属性’type’:QName值’covered-state’不解析为(n)简单类型定义.
WXS模式memory.xsd无法编译

继承人负责的代码

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.example.com">

    <xsd:simpleType name="covered-state">
        <xsd:union>
            <xsd:simpleType>
                <xsd:restriction base="xsd:integer">
                    <xsd:enumeration value="0"/>
                    <xsd:enumeration value="1"/>
                </xsd:restriction>
            </xsd:simpleType>
            <xsd:simpleType>
                <xsd:restriction base="xsd:string">
                    <xsd:enumeration value="COVERED"/>
                    <xsd:enumeration value="UNCOVERED"/>
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:union>
    </xsd:simpleType>

    <xsd:complexType name="MemoryCard">
        <xsd:attribute name="current-state" type="covered-state" use="required"/> <!-- here i get the error -->
    </xsd:complexType>

</xsd:schema>

所以这应该做的是联合字符串和整数的枚举,以便xml文件接受属性当前状态的“0”或“1”或“覆盖”或“未密封”.

有人能指出我正确的方向吗?谢谢!

解决方法

你的建议也会奏效,但我这样解决了:

<xsd:attribute name="current-state" use="required">
        <xsd:simpleType>    
            <xsd:union>
                <xsd:simpleType>
                    <xsd:restriction base="xsd:integer">
                        <xsd:enumeration value="0"/>
                        <xsd:enumeration value="1"/>
                    </xsd:restriction>
                </xsd:simpleType>
                <xsd:simpleType>
                    <xsd:restriction base="xsd:string">
                        <xsd:enumeration value="COVERED"/>
                        <xsd:enumeration value="UNCOVERED"/>
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:union>
        </xsd:simpleType>
    </xsd:attribute>

不管怎么说,还是要谢谢你!

猜你在找的XML相关文章