I’m trying to make two XML attributes to be mutually exclusive. How can one create an XSD schema to capture this kind of scenario?
I would like to have one of these
<elem value='1' /> <elem ref='something else' />
but not
<elem value='1' ref='something else' />
Since RelaxNG was mentioned in Alnitak’s answer, here is a solution with RelaxNG (a language which is, in most cases, better than W3C Schema). Do note the OR (|) in the definition of elem:
If I have this XML file:
It is accepted by rnv and xmlint:
If I add in the XML file:
I get validation errors, as I want (do note that the error messages are suboptimal):