Domanda

Qualcuno può indicarmi il motivo per cui l'elemento unico nel mio XSD non sta forzando l'unicità? Ciò dovrebbe generare un errore perché l'ultimo elemento ScreenResult non contiene un valore univoco per l'attributo Type . Dovrei anche notare che sono veramente dopo aver forzato uno di ogni Tipo in ScreenResults ( ScreenResult deve esistere 3 volte, ci sono 3 tipi di schermi e sto richiedendo l'unicità), quindi se c'è un modo migliore per farlo, lo sono anche io.

Grazie.

Ecco il mio frammento XML:

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

Ecco il mio frammento XSD (nota anche che i miei frammenti XSD originali si estendono su più file ma ho verificato che tutti i miei spazi dei nomi sono corretti):

<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>
È stato utile?

Soluzione

Sto pubblicando la mia soluzione per chiunque incontri questo problema.
Anche se avevo affermato che tutti i miei spazi dei nomi erano corretti, questo era ovviamente il problema. Tutti gli spazi dei nomi erano corretti tranne sull'elemento univoco stesso.
Ho erroneamente supposto che l'elemento univoco non avrebbe avuto bisogno di aggiungere un prefisso a uno spazio dei nomi come era nel contesto. Ma non è così. Dato che ho dichiarato uno spazio dei nomi predefinito per il file, avevo ancora bisogno del prefisso.

Quindi la mia unica modifica, e la soluzione, è la seguente:

<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>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top