كيف تجعل 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