其利用XS一个问题:独一无二 [英] Having a problem utilizing xs:unique

查看:143
本文介绍了其利用XS一个问题:独一无二的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以点我,为什么在我的XSD独特元素不是逼着独特的烦躁?这应该抛出一个错误,因为最后ScreenResult元素不包含的类型属性的独特的价值。我还应该注意到,我真的迫使ScreenResults中的每个类型的一个(ScreenResult需要存在3次,有3个类型的屏幕,我需要唯一岬)之后,所以如果有一个更好的方式来实现这一目标,我所有的这一点。谢谢你。

下面是我的XML片段:

 < ScreenResults>
    < ScreenResult TYPE =屏A型> 1 LT; / ScreenResult>
    < ScreenResult TYPE =屏B型> 1 LT; / ScreenResult>
    &所述; ScreenResult类型=画面类型B→2&下; / ScreenResult>
< / ScreenResults>

下面是我的XSD片段(也注意到,我原来的XSD片段跨越多个文件,但我已经验证了我所有的命名空间是正确的):

 < XS:元素的名称=ScreenResultsTYPE =导入:ScreenResults的minOccurs =0的maxOccurs =1>
    < XS:唯一的名称=UniqueScreenResults>
        < XS:选择的XPath =ScreenResult/>
        < XS:现场的XPath =@类型/>
    < / XS:独特的>
< / XS:组件><! - ============ ScreenResults ============= - >
< XS:复杂类型名称=ScreenResults>
    &所述; XS:序列的minOccurs =1maxOccurs的=1>
        < XS:元素的名称=ScreenResult的minOccurs =3的maxOccurs =3>
            < XS:复杂类型>
                < XS:simpleContent的>
                    < XS:扩展基板=枚举:ScreenResult>
                        < XS:属性名称=类型TYPE =枚举:ScreenType使用=需要/>
                    < / XS:扩展>
                < / XS:simpleContent的>
            < / XS:复杂类型>
        < / XS:组件>
    < / XS:序列>
< / XS:复杂类型><! - ============= ScreenType ============= - >
< XS:简单类型名称=ScreenType>
    < XS:限制基地='XS:令牌'>
        < XS:枚举值='屏A型'>
            < XS:注释>
                < XS:文件> 1 LT; / XS:文件>
            < / XS:注释>
        < / XS:枚举>
        < XS:枚举值='屏B型'>
            < XS:注释>
                < XS:文件> 2'; / XS:文件>
            < / XS:注释>
        < / XS:枚举>
        < XS:枚举值='屏幕类型C'>
            < XS:注释>
                < XS:文件>第3版; / XS:文件>
            < / XS:注释>
        < / XS:枚举>
    < / XS:限制>
< / XS:简单类型><! - ============ ============ ScreenResult - >
< XS:简单类型名称=ScreenResult>
    < XS:限制基地='XS:令牌'>
        < XS:枚举值='1'>
            < XS:注释>
                < XS:文件>积极< / XS:文件>
            < / XS:注释>
        < / XS:枚举>
        < XS:枚举值='2'>
            < XS:注释>
                < XS:文件>&负LT; / XS:文件>
            < / XS:注释>
        < / XS:枚举>
        < XS:枚举值='3'>
            < XS:注释>
                < XS:文件>不给予< / XS:文件>
            < / XS:注释>
        < / XS:枚举>
    < / XS:限制>
< / XS:简单类型>


解决方案

我张贴我为别人谁运行到这个问题的解决方案。虽然我曾断言,我所有的命名空间是正确的,那是当然的问题。所有的命名空间,所不同的独特元素本身是正确的。我错误地假定独特的元素就不需要preFIX一个命名空间,因为它是在范围内。但事实并非如此。自从我做了申报文件的默认名称空间,我仍然需要preFIX。所以,我唯一的变化,和解决方案,如下:

 < XS:元素的名称=ScreenResultsTYPE =导入:ScreenResults的minOccurs =0的maxOccurs =1>
    < XS:唯一的名称=UniqueScreenResults>
        < XS:选择的XPath =输入:ScreenResult/>
        < XS:现场的XPath =@类型/>
    < / XS:独特的>
< / XS:组件>

Can anyone point me as to why the unique element in my XSD is not forcing unique-ness? This should throw an error because the last ScreenResult element does not contain a unique value for the Type attribute. I should also note that I'm truly after forcing one of each Type within ScreenResults (ScreenResult is required to exist 3 times, there are 3 types of screens and I am requiring unique-ness) so if there is a better way to accomplish that, I'm all for that as well. Thank you.

Here is my XML snippet:

<ScreenResults>
    <ScreenResult Type="Screen Type A">1</ScreenResult>
    <ScreenResult Type="Screen Type B">1</ScreenResult>
    <ScreenResult Type="Screen Type B">2</ScreenResult>
</ScreenResults>

Here is my XSD snippet (also note that my original XSD snippets span multiple files but I have verified all of my namespaces are correct):

<xs:element name="ScreenResults" type="import:ScreenResults" minOccurs="0" maxOccurs="1">
    <xs:unique name="UniqueScreenResults">
        <xs:selector xpath="ScreenResult" />
        <xs:field xpath="@Type" />
    </xs:unique>
</xs:element>

<!--============  ScreenResults  =============-->
<xs:complexType name="ScreenResults">
    <xs:sequence minOccurs="1" maxOccurs="1">
        <xs:element name="ScreenResult" minOccurs="3" maxOccurs="3">
            <xs:complexType>
                <xs:simpleContent>
                    <xs:extension base="enum:ScreenResult">
                        <xs:attribute name="Type" type="enum:ScreenType" use="required" />
                    </xs:extension>
                </xs:simpleContent>
            </xs:complexType>
        </xs:element>
    </xs:sequence>
</xs:complexType>

<!--=============  ScreenType  =============-->
<xs:simpleType name="ScreenType">
    <xs:restriction base='xs:token'>
        <xs:enumeration value='Screen Type A' >
            <xs:annotation>
                <xs:documentation>1</xs:documentation>
            </xs:annotation>
        </xs:enumeration>
        <xs:enumeration value='Screen Type B' >
            <xs:annotation>
                <xs:documentation>2</xs:documentation>
            </xs:annotation>
        </xs:enumeration>
        <xs:enumeration value='Screen Type C' >
            <xs:annotation>
                <xs:documentation>3</xs:documentation>
            </xs:annotation>
        </xs:enumeration>
    </xs:restriction>
</xs:simpleType>

<!--============  ScreenResult  ============-->
<xs:simpleType name="ScreenResult">
    <xs:restriction base='xs:token'>
        <xs:enumeration value='1' >
            <xs:annotation>
                <xs:documentation>Positive</xs:documentation>
            </xs:annotation>
        </xs:enumeration>
        <xs:enumeration value='2' >
            <xs:annotation>
                <xs:documentation>Negative</xs:documentation>
            </xs:annotation>
        </xs:enumeration>
        <xs:enumeration value='3' >
            <xs:annotation>
                <xs:documentation>Not administered</xs:documentation>
            </xs:annotation>
        </xs:enumeration>
    </xs:restriction>
</xs:simpleType>

解决方案

I'm posting my solution for anyone else who runs into this problem. Although I had asserted that all of my namespaces were correct, that was, of course the problem. All of the namespaces were correct EXCEPT on the unique element itself. I erroneously assumed that the unique element would not need to prefix a namespace as it was within the context. But that is not the case. Since I did declare a default namespace for the file, I still needed the prefix. So my only change, and the solution, is as follows:

<xs:element name="ScreenResults" type="import:ScreenResults" minOccurs="0" maxOccurs="1">
    <xs:unique name="UniqueScreenResults">
        <xs:selector xpath="import:ScreenResult" />
        <xs:field xpath="@Type" />
    </xs:unique>
</xs:element>

这篇关于其利用XS一个问题:独一无二的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆