Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xml simple type with enumeration and union

parsing the following xml schema produces this error:

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

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.

Can someone point me in the right direction? Thanks!

like image 677
hooch Avatar asked Feb 24 '23 10:02

hooch


2 Answers

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!

like image 133
hooch Avatar answered Mar 08 '23 12:03

hooch


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

like image 25
Michael Kay Avatar answered Mar 08 '23 13:03

Michael Kay