Let's look at another example to better understand how keys and references work. This time, I'll leave the all-too-human world of supermarkets and travel back to that galaxy far, far away, to see exactly what's sitting in the cargo hold of two of the better-known starships in the Star Wars fleet.
Now, let's suppose I wanted to add a couple more droids to the Falcon. Sure,
I could add another <ship> element with the same name...or I could do the smart thing, and add another <droid> element to the existing definition. As discussed in the previous example, the latter option is much cleaner, and also fairly easy to implement via the <xsd:unique> element. Here's the relevant snippet of the updated schema definition:
In order to verify this, you can try creating two <ship> elements with the
same "name", and seeing your XML validator throw up all over the screen. It's always fun to watch, and it doesn't hurt anything!