title: XSD schema attempt to make attribute value unique
body: <p>I have been trying to use xs:unique with no success so far. I have the following simple schema:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
      &lt;xs:schema xmlns="http://testuri/test.xsd" 
        xmlns:xs="http://www.w3.org/2001/XMLSchema" 
        targetNamespace="http://testuri/test.xsd" 
        elementFormDefault="qualified" 
        id="XMLSchema1"&gt;
        &lt;xs:element name="root"&gt;
          &lt;xs:complexType&gt;
            &lt;xs:sequence&gt;
              &lt;xs:element name="items"&gt;
                &lt;xs:complexType&gt;
                  &lt;xs:sequence&gt;
                    &lt;xs:element name="item" maxOccurs="unbounded"&gt;
                      &lt;xs:complexType&gt;
                        &lt;xs:attribute name="id" type="xs:string" use="required"/&gt;
                      &lt;/xs:complexType&gt;
                    &lt;/xs:element&gt;
                  &lt;/xs:sequence&gt;
                &lt;/xs:complexType&gt;
              &lt;/xs:element&gt;
            &lt;/xs:sequence&gt;
          &lt;/xs:complexType&gt;
        &lt;/xs:element&gt;
      &lt;/xs:schema&gt;
  </code></pre>
  
  <p>Using this the following simple XML file is validated:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8" ?&gt;
      &lt;root xmlns="http://testuri/test.xsd"&gt;
        &lt;items&gt;
          &lt;item id="1"/&gt;
          &lt;item id="1"/&gt;
          &lt;item id="1"/&gt;
        &lt;/items&gt;
      &lt;/root&gt;
  </code></pre>
  
  <p>Now let's say we want to make attribute id unique. I was thinking of simply changing the schema to:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
      &lt;xs:schema 
        xmlns="http://testuri/test.xsd" 
        xmlns:xs="http://www.w3.org/2001/XMLSchema" 
        targetNamespace="http://testuri/test.xsd" 
        elementFormDefault="qualified" id="XMLSchema1"&gt;
        &lt;xs:element name="root"&gt;
          &lt;xs:complexType&gt;
            &lt;xs:sequence&gt;
              &lt;xs:element name="items"&gt;
                &lt;xs:complexType&gt;
                  &lt;xs:sequence&gt;
                    &lt;xs:element name="item" maxOccurs="unbounded"&gt;
                      &lt;xs:complexType&gt;
                        &lt;xs:attribute name="id" type="xs:string" use="required"/&gt;
                      &lt;/xs:complexType&gt;
                    &lt;/xs:element&gt;
                  &lt;/xs:sequence&gt;
                &lt;/xs:complexType&gt;
              &lt;/xs:element&gt;
            &lt;/xs:sequence&gt;
          &lt;/xs:complexType&gt;
          &lt;xs:unique name="itemKey"&gt;
            &lt;xs:selector xpath="items/item"/&gt;
            &lt;xs:field xpath="@id"/&gt;
          &lt;/xs:unique&gt;
        &lt;/xs:element&gt;
      &lt;/xs:schema&gt;
  </code></pre>
  
  <p>However the xml above still gets validated.</p>
  
  <p>I am most certain that the problem lies on the xpath of the selector. Any ideas?</p>