This question is not from any mock exam. I don't know if this is trivial to you, but I think it's a nice test on your understanding of schema key/keyref.
This document is validate (as report by xsv and MSXML4.0). But as you may note that I'd like to enforce the key on B's ID attribute, with A's Ref element referencing it.
So, what's the problem??
One example here
Copied from http://www.w3schools.com/schema/el_element.asp
Definition and Usage
The element element defines an element.
Parent elements: schema, choice, all, sequence, group
How this work? xsd:element has a wrong parent.
Copied from Kenneth Tsuei's post
I think I've found the problem or a solution. After I made certain changes, the key/keyref both got checked by the validator. The document becomes invalid as you desired.
However, I do not quite understand it yet. I'll keep you posted probably tonight.
It is even more complicated in your case than the article described. I don't want to spend more time on it, and I'll quit for now.
However, I learned more schema during this process than I'd expected. Thanks for raising this question.