Frage

Kann mir jemand zeigen, warum das einzigartige Element in meinem XSD ist einzigartig-ness nicht zwingen? Dies sollte einen Fehler aus, weil das letzte ScreenResult Element enthält keinen eindeutigen Wert für das Attribut Type. Ich sollte auch beachten, dass ich wirklich nach einer jeder Type innerhalb ScreenResults zwingen (ScreenResult erforderlich 3-mal existieren, gibt es drei Arten von Bildschirmen und ich erfordern einzigartige-ness) so, wenn es eine bessere Art und Weise zu erreichen, dass , ich bin auch für alles.

Danke.

Hier ist mein 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>

Hier ist mein XSD-Schnipsel ist (auch beachten, dass mein ursprünglicher XSD-Schnipsel mehr Dateien überspannen, aber ich habe all meine Namensräume überprüft korrekt sind):

<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>
War es hilfreich?

Lösung

Ich poste meine Lösung für alle anderen, die in dieses Problem läuft.
Obwohl ich, dass alle meine Namensräume waren korrekt geltend gemacht hatte, dass war natürlich das Problem. Alle der Namensräume waren korrekt außer auf der einzigartigen Element selbst.
Ich nahm fälschlicherweise, dass das einzigartige Element würde kein Namespacepräfix muß, wie es im Kontext war. Aber das ist nicht der Fall. Da ich einen Standard-Namespace für die Datei deklarieren tat, brauchte ich noch das Präfix.

So ist meine einzige Änderung, und die Lösung ist wie folgt:

<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>
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top