我试图用ID
类型属性限制两种类型的工会:XSD:定义的ID类型的限制与联盟
<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>
所以基本思想是属性值应该与枚举{from/to/cc/bcc/subject/sendTime}或模式“attachment \ d + -metadata”匹配。
当使用JAXB我收到以下错误验证:
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.
这对我来说很有意义。 metaDataID
的新定义不再具有类型ID
。但是我不能在simpleType
或union
元素上指定类型,所以我不知道如何指定联合的结果也是ID
类型。我也曾尝试:
<attribute name="metaDataID" use="required">
<simpleType>
<restriction base="ID">
<union>
...
</union>
</restriction>
</simpleType>
</attribute>
但限制不允许工会它们下面。这甚至有可能吗?
谢谢!无论如何,我会使用你的模式,因为它更容易阅读。它看起来像XSD 1.1在这方面没有帮助,虽然我不能确定,因为我不认为JAXB支持1.1。 – 2015-04-06 05:42:09