Question: How can I restrict an attribute to not allow a particular value?

For instance, I have an `<xs:key/>` on an `Id` attribute of an element, but some yahoo has gone and thrown a magic number in there so now I cannot allow `3`, but `1`, `2`, and `5` are perfectly acceptable.

Answer: 
Have you tried having a look at the restriction tag [link text](http://www.w3schools.com/schema/schema_facets.asp), the code below, it should give you a tag called Id which only allows integers that doesn't start with a 3

```
<xs:key name="Id">
    <xs:simpleType>
        <xs:restriction base="xs:integer">
            <xs:pattern value="[^3]\d*"/>
       </xs:restriction>
  </xs:simpleType>
</xs:key>

```
If your IDs are integers, and you want to allow any integer except 3, your best bet (it seems to me) is not regexes on patterns, because as other commentors have observed it's easy to leave holes accidentally, but to define a subtype of integers for integers less than 3, and another for integers greater than tree, and then define their union. Your attribute gets the union type. And voila, you accept any integer but 3. All you have to do is hunt down the person who make 3 magic, and ensure that they don't add more magic numbers.

In XSD 1.1, you could also get around this awkwardness by adding an assertion that constrains the value to be not equal to 3.