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

时间:2022-02-18 19:16:10

parsing the following xml schema produces this error:

解析以下xml架构会产生此错误:

element attribute: Schemas parser error : attribute decl. 'current-state', attribute 'type': The QName value 'covered-state' does not resolve to a(n) simple type definition. WXS schema memory.xsd failed to compile

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

heres the responsible code:

继承人负责的代码:

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

So what this is supposed to do is to union an enumeration of strings and ints so that the xml file accepts "0" or "1" or "COVERED" or "UNCOVERED" for attribute current state.

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

Can someone point me in the right direction? Thanks!

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

2 个解决方案

#1


5  

your suggestions would work too but i solved it like this:

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

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

thanks anyway!

#2


2  

type="covered-state" is a reference to a type in no namespace, but you want a reference to a type with local name "covered-state" in namespace "http://www.example.com". To achieve that you need to bind a prefix (say e) to this namespace and refer to it as type="e:covered-state".

type =“covered-state”是对无命名空间中的类型的引用,但是您希望在名称空间“http://www.example.com”中引用具有本地名称“covered-state”的类型。要实现这一点,您需要将前缀(例如e)绑定到此命名空间,并将其称为type =“e:covered-state”。

#1


5  

your suggestions would work too but i solved it like this:

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

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

thanks anyway!

#2


2  

type="covered-state" is a reference to a type in no namespace, but you want a reference to a type with local name "covered-state" in namespace "http://www.example.com". To achieve that you need to bind a prefix (say e) to this namespace and refer to it as type="e:covered-state".

type =“covered-state”是对无命名空间中的类型的引用,但是您希望在名称空间“http://www.example.com”中引用具有本地名称“covered-state”的类型。要实现这一点,您需要将前缀(例如e)绑定到此命名空间,并将其称为type =“e:covered-state”。