Как сделать univoque мое перечисление по xs: уникальным

StackOverflow https://stackoverflow.com/questions/1428886

  •  07-07-2019
  •  | 
  •  

Вопрос

Может ли кто-нибудь указать мне, почему уникальный элемент в моем XSD не вызывает уникальность? Это должно вызвать ошибку, поскольку последний элемент ScreenResult не содержит уникального значения для атрибута Type . Я также должен отметить, что я действительно после принудительного применения одного из Type в ScreenResults ( ScreenResult должен существовать 3 раза, есть 3 типы экранов, и я требую уникальности), так что если есть лучший способ сделать это, я тоже за это.

Спасибо.

Вот мой фрагмент XML:

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

Вот мой фрагмент XSD (также обратите внимание, что мои исходные фрагменты XSD охватывают несколько файлов, но я проверил, что все мои пространства имен верны):

<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>
Это было полезно?

Решение

Я публикую свое решение для всех, кто сталкивается с этой проблемой.
Хотя я утверждал, что все мои пространства имен были правильными, это была, конечно, проблема. Все пространства имен были правильными , кроме для самого уникального элемента.
Я ошибочно предположил, что уникальному элементу не нужно будет добавлять префикс к пространству имен, как это было в контексте. Но это не тот случай. Так как я объявил пространство имен по умолчанию для файла, мне все еще нужен был префикс.

Итак, мое единственное изменение и решение следующие:

<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>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top