What is the difference between using xsd:unique and xsd:key?
xsd:unique does not require the field to exist for the selector. If the field exists, its value should be unique.
xsd:key requires the field to exist for all selector results. Every element in the selector should have a key.
Note that xsd:keyref is not a requirement for xsd:key, the xsd:key can be there withoug any xsd:keyref.
xsd:key is unique AND is used for a collection of elements a key within a scope xsd:unique is just unique within a scope.
Hope this helps...
I found my own answer:
It all has to do with cardinality:
xsd:key is used for (0..N) and (1..1) multiplicity. xsd:unique is used for optional (0..1) multiplicity. This is also the reason why a the selected field in a xsd:unique can be nill.
Source of my answer: http://www.xml.com/lpt/a/987
it is similar to database.
key field is like primarykey.. unique and id
unique field is not a key but it has to be unique...
See http://www.w3.org/TR/2004/REC-xmlschema-0-20041028/primer.html#quartelyReport.
In the example described in the link the "keyRefed" elements are the values of the number attributes of the parts of the zip of the regions and the "keyed" elements are the values of the number attribute of the part of the parts.
Unique declares that the values must be unique but can be null also, key - that they must be unique. Both types can be references by "keyRefed" elements.