I've tried several ways to achieve a xsd schema for the following xml
example, but failed to do so.
Valid:
<Person>
<Interest>Movies</Interest>
<Interest>Computers</Interest>
</Person>
<Person>
<Interest>Movies</Interest>
</Person>
Non-valid:
<Person>
<Interest>Movies</Interest>
<Interest>Movies</Interest>
</Person>
In this example the Interests are an enumeration.
Is it possible to make a restriction for the repeated elements so that
all elements have a different value?
All help is appreciated,
Hans
I have now tested the following schema, and it works...
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema
xmlns:xs="
http://www.w3.org/2001/XMLSchema"
targetNamespace="uri:fo2"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
xmlns="uri:fo2"
xmlns:fo2="uri:fo2">
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element ref="Person"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Person">
<xs:complexType>
<xs:sequence>
<xs:element name="Interest"
type="InterestEnumType"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:unique name="PersonDistinctInterests">
<xs:selector xpath="fo2:Interest"/>
<xs:field xpath="."/>
</xs:unique>
</xs:element>
<xs:simpleType name="InterestEnumType">
<xs:restriction base="xs:string">
<xs:enumeration value="Computers"/>
<xs:enumeration value="Movies"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
In the example below, an error occurs on the second <Interest> having a value
of "Movies" in the final <Person> as a result of the xs:unique constraint.
Here's what's happening:
Because the unique constraint is defined within the Person element, the scope
of the constraint is the content of an individual Person element (descendants
of different <Person>s will not be compared to each other). <selection>
supplies an xpath expression of what self-or-descendant elements of the
<Person> need to be checked against each other for uniqueness, and the
combination of <field> items (in this case, 1 of them) indicate the
combination of self-or-descendant nodes of each selection containing the
combination of values used to determine uniqueness by. In this case, we have
one field (".") which is the element itself.
<?xml version="1.0" encoding="UTF-8"?>
<fo2:Root
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="uri:fo2 fo2.xsd"
xmlns:fo2="uri:fo2"
xmlns="uri:fo2">
<Person>
<Interest>Movies</Interest>
<Interest>Computers</Interest>
</Person>
<Person>
<Interest>Movies</Interest>
<Interest>Computers</Interest>
</Person>
<Person>
<Interest>Movies</Interest>
<Interest>Movies</Interest>
</Person>
</fo2:Root>