Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有枚举和并集的xml简单类型_Xml_Types_Xsd_Union_Enumeration - Fatal编程技术网

带有枚举和并集的xml简单类型

带有枚举和并集的xml简单类型,xml,types,xsd,union,enumeration,Xml,Types,Xsd,Union,Enumeration,分析以下xml架构会产生此错误: 元素属性:架构分析器错误:属性decl'“当前状态”,属性“类型”:QName值“covered state”未解析为(n)个简单类型定义。 WXS架构内存.xsd未能编译 以下是责任代码: <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.com"> <xsd:simpleType name

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

元素属性:架构分析器错误:属性decl'“当前状态”,属性“类型”:QName值“covered state”未解析为(n)个简单类型定义。 WXS架构内存.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>

因此,这应该做的是联合字符串和int的枚举,以便xml文件接受属性当前状态的“0”或“1”或“COVERED”或“UNCOVERED”


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

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

您的建议也可以,但我是这样解决的:

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


无论如何谢谢你

嗯,好吧,我已经成功了。。我想发布答案,但作为一个新用户,我必须再等8个小时。所以如果我记得的话,也许我会把它贴出来。或者,可以删除
xsd:schema
元素中的目标名称空间。我想,这取决于名称空间是否真正重要。