限制XML模式中的属性值

时间:2015-01-14 07:09:30

标签: xml xsd

是否可以在XML模式中限制属性值的组合? 我有一个带有两个属性的标签,我想允许它们的值的某些组合。例如。如果attribute_1具有值" A",则attribute_2必须没有值" B"。

1 个答案:

答案 0 :(得分:2)

在XSD 1.1中,您可以使用assertions。像(未经测试)的东西:

<xs:element name="SomeType">
  <xs:complexType>
    <xs:attribute name="attribute_1" type="xs:string">
    <xs:attribute name="attribute_2" type="xs:string"/>
    <xs:assert test="if (@attribute_1 = 'A') then @attribute_2 != 'B' else true()"/>
  </xs:complexType>
</xs:element>

查看更多示例here

相关问题