假设我希望元素 XXX 可以具有属性 AAA 和属性 BBB 成对,或者属性 CCC 和 DDD 成对,但切勿将 AAA 与 DDD 或类似的混合。
我该如何定义它?
谢谢
最佳答案
这不是 xsd 中可用的功能。如果要将属性限制为两个分组,则需要定义两个元素,每个元素对应一个属性分组。例如:
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
<xs:complexType>
<xs:choice>
<xs:element name="MyType1">
<xs:complexType>
<xs:attribute name="AAA" type="xs:string" />
<xs:attribute name="DDD" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="MyType2">
<xs:complexType>
<xs:attribute name="BBB" type="xs:string" />
<xs:attribute name="CCC" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
希望这对您有帮助。
关于attributes - 如何在 XSD 中定义所需属性组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6497095/