【发布时间】:2011-06-30 16:58:31
【问题描述】:
在使用 XML Schema 1.1 时,我想定义一个完全一起出现的属性组,即 attributeGroup 中的所有属性要么存在要么不存在。在下面的示例中,我希望 <anelement> 具有两个属性(attr_one 和 attr_two)或两个属性都不存在,而不是只存在一个属性。
<attributeGroup name="attrgroup">
<attribute name="attr_one" />
<attribute name="attr_one" />
</attributeGroup>
<element name="anelement">
<complexType>
<attributeGroup ref="attrgroup" />
</complexType>
</element>
据我了解,XML Schema 1.0 无法指定这些属性关系(对吗?)。在 XSD 1.1 中指定它们的最佳方式是什么?我想我可以使用assert 来指定关系,如下所示:
<element name="anelement">
<complexType>
<attributeGroup ref="attrgroup" />
<assert test="(@attr_one and @attr_two) or not(@attr_one or @attr_two)" />
</complexType>
</element>
但我希望在 1.1 中添加一些内容,允许我使用现有语言指定关系,例如attributeGroups 上的 use 属性。在 XML Schema 1.1 中指定这种关系的最佳方式是什么?
【问题讨论】:
-
酷,我不知道 XML Schema 1.1 提供了这样的断言。
-
您使用的是哪种 XML Schema 1.1 实现?撒克逊人?
-
是的,1.1。有完整的 XPath 断言。 Xerces-J 支持我想要使用的 1.1 的所有部分,所以我现在使用它进行验证。希望其他工具(尤其是 OXM)能够很快赶上。