I am trying to make an element’s content conditional on an enumerated attribute. The content for each attribute will be completely different. For instance:
<?xml version="1.0" encoding="utf-8"?>
<foo type="bar">
<bargress num="5"/>
<bargress num="8"/>
</foo>
and
<?xml version="1.0" encoding="utf-8"?>
<foo type="kan">
<kangress say="hi"/>
<kangress say="all"/>
</foo>
would validate, but
<?xml version="1.0" encoding="utf-8"?>
<foo type="kan">
<bargress num="5"/>
<bargress num="8"/>
<kangress say="hi"/>
<kangress say="all"/>
</foo>
would not.
Is this possible, and if so how would I go about it?
What you are describing is essentially “Conditional Type Assignment” which is one of the new features in XSD 1.1 (available today in Xerces and Saxon).
The nearest you can get in XSD 1.0 is to rename your “type” attribute as xsi:type, and have it refer to the name of a complex type defined in your schema.