tags:

views:

148

answers:

1

I have the following XML:

<Content name="contentName1">
    <!-- Some sub elements here -->
</Content>

<Sequence Name="sequenceName1">
    <Content name="contentName1" />
    <!-- Some sub elements here -->
</Sequence>

with the following XSD

<xs:element maxOccurs="unbounded" name="Content">
    <xs:complexType>
        <xs:attribute name="Name" type="xs:string" use="required" />
        <!-- other definitions here -->
     </xs:complexType>
</xs:element>

<xs:element maxOccurs="unbounded" name="Sequence">
    <xs:complexType>
        <xs:sequence>
            <xs:element maxOccurs="unbounded" name="Content">
                <xs:complexType>
                    <xs:attribute name="ContentName" type="xs:string" use="required" />
                </xs:complexType>
            </xs:element>
        </xs:sequence>
        <xs:attribute name="Name" type="xs:string" use="required" />
    </xs:complexType>
</xs:element>

In the XSD, how can I tell to the ContentName attribute of the Content elements of Sequence to only accepts value declared in the ContentName of Content elements?

e.g: with the XML provided above, only contentName1 will be accepted in the Content of sequence.

+1  A: 

Identity constraint definitions are used for enforcing the unique, primary key and foreign key relations. you need to first define a key element for the content element and then use a keyref in the inner content element for the schema validator to enforce the condition you mentioned.
Refer the below link it has some examples as well, also the tutorial in xfront for xsd covers some examples -

http://www.w3.org/TR/xmlschema11-1/#Identity-constraint_Definition_details
http://www.xfront.com/files/xml-schema.html

keshav.veerapaneni