1

ユニークな要素を作成しようとしています。これが私のコードの一部です。

<complexType name="DeliveryOrder">
    <sequence>
        <element name="Depot" type="tns:County" minOccurs="1" maxOccurs="1"></element>
        <element name="CustomerDetails" type="tns:CustomerDetails" minOccurs="1" maxOccurs="1"></element>
        <element name="ItemsToBeDelivered"
            type="tns:ItemsToBeDelivered" maxOccurs="unbounded" minOccurs="1">
        </element>
    </sequence>
</complexType>

<complexType name="CustomerDetails">
    <sequence>
        <element name="FirstName">
            <simpleType>
                <restriction base="string">
                    <pattern value="[a-zA-Z][a-z][a-z]*"></pattern>
                </restriction>
            </simpleType>
        </element>
        <element name="Surname">
            <simpleType>
                <restriction base="string">
                    <pattern value="[a-z{^}A-Z][a-z][a-z]*"></pattern>
                </restriction>
            </simpleType>
        </element>
        <element name="AddressLine1">
            <simpleType>
                <restriction base="string">
                    <minLength value="4"></minLength>
                    <whiteSpace value="collapse"></whiteSpace>
                </restriction>
            </simpleType>
        </element>
        <element name="AddressLine2">
            <simpleType>
                <restriction base="string">
                    <minLength value="4"></minLength>
                    <whiteSpace value="collapse"></whiteSpace>
                </restriction>
            </simpleType>
        </element>
        <element name="AddressLine3" type="string">
        </element>
        <element name="County" type="tns:County" maxOccurs="1" minOccurs="1"></element>
    </sequence>
</complexType>

<complexType name="County">
    <choice>
        <element name="CountyName">
            <simpleType>
                <restriction base="string">
                    <enumeration value="Dublin"></enumeration>
                    <enumeration value="Cork"></enumeration>
                    <enumeration value="Kildare"></enumeration>
                    <enumeration value="Waterford"></enumeration>
                    <enumeration value="Wicklow"></enumeration>
                </restriction>
            </simpleType>
        </element>
    </choice>
</complexType>

<complexType name="DaysForDelivery">
    <sequence>
        <element name="Day">
            <simpleType>
                <restriction base="string">
                    <enumeration value="Monday"></enumeration>
                    <enumeration value="Tuesday"></enumeration>
                    <enumeration value="Wednesday"></enumeration>
                    <enumeration value="Thursday"></enumeration>
                    <enumeration value="Friday"></enumeration>
                </restriction>
            </simpleType>
        </element>
    </sequence>
</complexType>

<element name="DeliveryOrder" type="tns:DeliveryOrder"></element>

<complexType name="ItemsToBeDelivered">
    <sequence>
        <element name="DaysForDelivery" type="tns:DaysForDelivery"
            maxOccurs="unbounded" minOccurs="1">
        </element>
        <element name="Item" type="tns:Item" maxOccurs="unbounded" minOccurs="1"></element>
    </sequence>
</complexType>

<complexType name="Item">
    <sequence>
        <element name="Description">
            <simpleType>
                <restriction base="string">
                    <enumeration
                        value="Regular Milk - 1 litre carton.">
                    </enumeration>
                    <enumeration
                        value="Low Fat Milk - 1 litre carton.">
                    </enumeration>
                    <enumeration
                        value="Strawberry Yoghurt - 100ml pot">
                    </enumeration>
                    <enumeration
                        value="Raspberry Yoghurt - 100ml pot">
                    </enumeration>
                    <enumeration value="Cream - 125ml carton"></enumeration>
                    <enumeration value="Cream - 250ml carton"></enumeration>
                </restriction>
            </simpleType>
        </element>
        <element name="Quantity">
            <simpleType>
                <restriction base="int">
                    <minInclusive value="1"></minInclusive>
                </restriction>
            </simpleType>
        </element>
    </sequence>
</complexType>

そこで、「DaysForDelivery」の要素「Day」をユニークにしたい。例: 月曜日に X のアイテムを持っていて、それ以降は月曜日を使用できなくなります。一意のタグを使用する必要があることはわかっており、多くの例を調べましたが、xpaths を台無しにしています。

前もって感謝します

4

1 に答える 1

1

更新:変更されたXSDは次のとおりです。

<?xml version="1.0" encoding="utf-8" ?>
<!--XML Schema generated by QTAssistant/XML Schema Refactoring (XSR) Module (http://www.paschidev.com)-->
<schema targetNamespace="http://tempuri.org/XMLSchema.xsd" elementFormDefault="qualified" xmlns:tns="http://tempuri.org/XMLSchema.xsd" xmlns="http://www.w3.org/2001/XMLSchema">
    <complexType name="DeliveryOrder">
        <sequence>
            <element name="Depot" type="tns:County" minOccurs="1" maxOccurs="1"></element>
            <element name="CustomerDetails" type="tns:CustomerDetails" minOccurs="1" maxOccurs="1"></element>
            <element name="ItemsToBeDelivered" type="tns:ItemsToBeDelivered" maxOccurs="unbounded" minOccurs="1">
                <unique name="UQ">
                    <selector xpath="tns:DaysForDelivery/tns:Day"/>
                    <field xpath="."/>
                </unique>
            </element>
        </sequence>
    </complexType>
    <complexType name="CustomerDetails">
        <sequence>
            <element name="FirstName">
                <simpleType>
                    <restriction base="string">
                        <pattern value="[a-zA-Z][a-z][a-z]*"></pattern>
                    </restriction>
                </simpleType>
            </element>
            <element name="Surname">
                <simpleType>
                    <restriction base="string">
                        <pattern value="[a-z{^}A-Z][a-z][a-z]*"></pattern>
                    </restriction>
                </simpleType>
            </element>
            <element name="AddressLine1">
                <simpleType>
                    <restriction base="string">
                        <minLength value="4"></minLength>
                        <whiteSpace value="collapse"></whiteSpace>
                    </restriction>
                </simpleType>
            </element>
            <element name="AddressLine2">
                <simpleType>
                    <restriction base="string">
                        <minLength value="4"></minLength>
                        <whiteSpace value="collapse"></whiteSpace>
                    </restriction>
                </simpleType>
            </element>
            <element name="AddressLine3" type="string">
            </element>
            <element name="County" type="tns:County" maxOccurs="1" minOccurs="1"></element>
        </sequence>
    </complexType>

    <complexType name="County">
        <choice>
            <element name="CountyName">
                <simpleType>
                    <restriction base="string">
                        <enumeration value="Dublin"></enumeration>
                        <enumeration value="Cork"></enumeration>
                        <enumeration value="Kildare"></enumeration>
                        <enumeration value="Waterford"></enumeration>
                        <enumeration value="Wicklow"></enumeration>
                    </restriction>
                </simpleType>
            </element>
        </choice>
    </complexType>

    <complexType name="DaysForDelivery">
        <sequence>
            <element name="Day">
                <simpleType>
                    <restriction base="string">
                        <enumeration value="Monday"></enumeration>
                        <enumeration value="Tuesday"></enumeration>
                        <enumeration value="Wednesday"></enumeration>
                        <enumeration value="Thursday"></enumeration>
                        <enumeration value="Friday"></enumeration>
                    </restriction>
                </simpleType>
            </element>
        </sequence>
    </complexType>

    <element name="DeliveryOrder" type="tns:DeliveryOrder"></element>

    <complexType name="ItemsToBeDelivered">
        <sequence>
            <element name="DaysForDelivery" type="tns:DaysForDelivery" maxOccurs="unbounded" minOccurs="1">
            </element>
            <element name="Item" type="tns:Item" maxOccurs="unbounded" minOccurs="1"></element>
        </sequence>
    </complexType>

    <complexType name="Item">
        <sequence>
            <element name="Description">
                <simpleType>
                    <restriction base="string">
                        <enumeration value="Regular Milk - 1 litre carton.">
                        </enumeration>
                        <enumeration value="Low Fat Milk - 1 litre carton.">
                        </enumeration>
                        <enumeration value="Strawberry Yoghurt - 100ml pot">
                        </enumeration>
                        <enumeration value="Raspberry Yoghurt - 100ml pot">
                        </enumeration>
                        <enumeration value="Cream - 125ml carton"></enumeration>
                        <enumeration value="Cream - 250ml carton"></enumeration>
                    </restriction>
                </simpleType>
            </element>
            <element name="Quantity">
                <simpleType>
                    <restriction base="int">
                        <minInclusive value="1"></minInclusive>
                    </restriction>
                </simpleType>
            </element>
        </sequence>
    </complexType>
</schema>

ここに画像の説明を入力してください

有効なXMLのサンプル:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!-- Sample XML generated by QTAssistant (http://www.paschidev.com) -->
<DeliveryOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/XMLSchema.xsd">
    <Depot>
        <CountyName>Dublin</CountyName>
    </Depot>
    <CustomerDetails>
        <FirstName>Firstname</FirstName>
        <Surname>Surname</Surname>
        <AddressLine1>AddressLine11</AddressLine1>
        <AddressLine2>AddressLine21</AddressLine2>
        <AddressLine3>AddressLine31</AddressLine3>
        <County>
            <CountyName>Dublin</CountyName>
        </County>
    </CustomerDetails>
    <ItemsToBeDelivered>
        <DaysForDelivery>
            <Day>Monday</Day>
        </DaysForDelivery>
        <DaysForDelivery>
            <Day>Tuesday</Day>
        </DaysForDelivery>
        <Item>
            <Description>Regular Milk - 1 litre carton.</Description>
            <Quantity>1</Quantity>
        </Item>
        <Item>
            <Description>Regular Milk - 1 litre carton.</Description>
            <Quantity>1</Quantity>
        </Item>
    </ItemsToBeDelivered>
</DeliveryOrder>

あなたがあなたに変わるならばTuesdayMondayあなたは得る:

Error occurred while loading [], line 22 position 17
There is a duplicate key sequence 'Monday' for the 'http://tempuri.org/XMLSchema.xsd:UQ' key or  unique identity constraint.
Document1.xml is invalid.
于 2012-10-18T21:11:21.743 に答える