XMl Schema: Unique key values within parent <p>I have the following XML:</p> <pre><code> &lt;enumTypes xmlns="tempURI"&gt; &lt;enumType id="1"&gt; &lt;enumValue id="1" value="Item1"/&gt; &lt;enumValue id="2" value="Item2"/&gt; &lt;enumValue id="3" value="Item3"/&gt; &lt;/enumType&gt; &lt;enumType id="2"&gt; &lt;enumValue id="1" value="Item1"/&gt; &lt;enumValue id="2" value="Item2"/&gt; &lt;/enumType&gt; &lt;/enumTypes&gt; </code></pre> <p>I also have the following schema:</p> <pre><code> &lt;xs:element name="enumTypes"&gt; &lt;xs:complexType&gt; &lt;xs:sequence minOccurs="1" maxOccurs="unbounded"&gt; &lt;xs:element name="enumType"&gt; &lt;xs:complexType&gt; &lt;xs:sequence minOccurs="1" maxOccurs="unbounded"&gt; &lt;xs:element name="enumValue"&gt; &lt;xs:complexType&gt; &lt;xs:attribute name="id" type="xs:string" use="required"/&gt; &lt;xs:attribute name="value" type="xs:string" use="required"/&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;/xs:sequence&gt; &lt;xs:attribute name="id" type="xs:string"/&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;xs:key name="enumTypeKey"&gt; &lt;xs:selector xpath="enumTypes/enumType"/&gt; &lt;xs:field xpath="@id"/&gt; &lt;/xs:key&gt; &lt;xs:key name="enumValueKey"&gt; &lt;xs:selector xpath="enumTypes/enumType/enumValue"/&gt; &lt;xs:field xpath="@id"/&gt; &lt;/xs:key&gt; </code></pre> <p>I'm trying to force the enumValue ID's to be unique WITHIN a enumType, but so far I can only get it to force them to be unique across ALL enumTypes.</p> <p>I'm guessing there's a problem with my selector XPath but I can't seem to get it sorted out.</p> <p>Any help would be appreciated!</p>