In using XML Schema 1.1, I’d like to define an attribute group that occurs entirely together, i.e. all the attributes in the attributeGroup are either present or not-present. In the following example, I’d like <anelement> to have both attributes (attr_one and attr_two) present or neither attribute present, never only a single attribute present.
<attributeGroup name="attrgroup">
<attribute name="attr_one" />
<attribute name="attr_one" />
</attributeGroup>
<element name="anelement">
<complexType>
<attributeGroup ref="attrgroup" />
</complexType>
</element>
As I understand it, XML Schema 1.0 cannot specify these attribute relationships (correct?). What is the best way to specify them in XSD 1.1? I figure that I can use assert to specify the relationship, something like the following:
<element name="anelement">
<complexType>
<attributeGroup ref="attrgroup" />
<assert test="(@attr_one and @attr_two) or not(@attr_one or @attr_two)" />
</complexType>
</element>
But I was hoping there was something added to 1.1 that would allow me to specify the relationship using the existing language, e.g. a use attribute on attributeGroups. What is the best way to specify this relationship in XML Schema 1.1?
Assertions are the way to do this. A simpler formulation is
or you could do