XSD: Defining a Restriction on ID type with Union



I am trying to restrict an attribute with type ID to a union of two types:





<attribute name="metaDataID" use="required">
<simpleType>
<union>
<simpleType>
<restriction base="ID">
<enumeration value="from" />
<enumeration value="to" />
<enumeration value="cc" />
<enumeration value="bcc" />
<enumeration value="subject" />
<enumeration value="sendTime" />
</restriction>
</simpleType>
<simpleType>
<restriction base="ID">
<pattern value="attachment\d+-metadata" />
</restriction>
</simpleType>
</union>
</simpleType>
</attribute>



So the basic idea is the attribute value should either match the enumeration {from/to/cc/bcc/subject/sendTime} or the pattern "attachment\d+-metadata".


When validating using JAXB I get the following error:



The attribute use 'metaDataID' in this type has type 'null', which is not validly derived from 'ID', the type of the matching attribute use in the base type.


This makes sense to me. The new definition of metaDataID no longer has type ID. However I cannot specify a type on the simpleType or union elements, so I don't know how to specify that the result of the union is also of type ID. I have also tried:





<attribute name="metaDataID" use="required">
<simpleType>
<restriction base="ID">
<union>
...
</union>
</restriction>
</simpleType>
</attribute>



but restrictions do not allow unions underneath them. Is this even possible?


No comments:

Post a Comment