Visual Studio gave me an error I can’t see is really against the XML schema definition.
When I have a unique constraint on a collection which element I Ref to it says
When the ref attribute is present, the type attribute and complexType, simpleType, key, keyref, and unique elements cannot be present.
Is this correct and if so am I forced to declare the child element within it’s parent?
<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://mysticwarlords.kaa/XMLSchema"
xmlns="http://mysticwarlords.kaa/XMLSchema"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="titletype">
<xs:restriction base="xs:string">
<xs:enumeration value="Warlord"/>
<xs:enumeration value="FirstMate"/>
<xs:enumeration value="Jester"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="warlord">
<xs:complexType>
<xs:sequence>
<xs:element name="warlordName" type="xs:string"/>
</xs:sequence>
<xs:attribute name="title" type="titletype" />
</xs:complexType>
</xs:element>
<xs:element name="warband">
<xs:complexType>
<xs:sequence>
<xs:element name="warbandName" type="xs:string" />
<xs:element name="warlords">
<xs:complexType>
<xs:sequence>
<xs:element ref="warlord" minOccurs="1" maxOccurs="unbounded">
<xs:unique name="eachTitleOnlyOnce">
<xs:selector xpath="warlord"/>
<xs:field xpath="@title"/>
</xs:unique>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Am I using the Unique correct?
EDIT
What about this:
<xs:complexType name="warlordtype">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="title" type="titletype" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:element name="warband">
<xs:complexType>
<xs:sequence>
<xs:element name="warbandName" type="xs:string" />
<xs:element name="warlords">
<xs:complexType>
<xs:sequence>
<xs:element name="warlord" type="warlordtype" minOccurs="1" maxOccurs="unbounded">
<xs:unique name="eachTitleOnlyOnce">
<xs:selector xpath="warlord"/>
<xs:field xpath="@title"/>
</xs:unique>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
Why wouldn’t this work?
Unique element can’t be in ref element. Check element definition.
Can you use this: