You can do it with the built-in schematron
<xsd:schema elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:complexType name="ConfigDef"> <xsd:annotation> <xsd:appinfo> <sch:pattern name="Test constraints on the ConfigDef element" xmlns:sch="http://purl.oclc.org/dsdl/schematron"> <sch:rule context="ConfigDef"> <sch:assert test="@NAME eq 'foo' and @VALUE = ('bar','baz')">Error message when the assertion condition is broken...</sch:assert> <sch:assert test="@NAME eq 'qux' and @VALUE = ('teh','xyz')">Error message when the assertion condition is broken...</sch:assert> </sch:rule> </sch:pattern> </xsd:appinfo> </xsd:annotation> <xsd:attribute name="NAME" type="xsd:string"> <xsd:annotation> <xsd:documentation>The name of this Config setting.</xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="VALUE" type="xsd:string"> <xsd:annotation> <xsd:documentation>The value of this Config setting.</xsd:documentation> </xsd:annotation> </xsd:attribute> </xsd:complexType> </xsd:schema>
Or you can do it with a relaxation scheme
element ConfigDef { (( attribute NAME {'foo'}, attribute VALUE {'bar'|'baz'}) | ( attribute NAME {'qux'}, attribute VALUE {'teh'|'xyz'})) }
nine9ths
source share