Xml XSD-两个不同属性的唯一值

Xml XSD-两个不同属性的唯一值,xml,xsd,xsd-1.0,Xml,Xsd,Xsd 1.0,可以在模式级别强制两个具有不同名称的属性的唯一值 <xs:complexType name="exampleType"> <xs:attribute name="first" type="xs:integer" use="required"/> <xs:attribute name="second" type="xs:integer"/> </xs:complexType> 如果first是1,second需要是其他值 编辑:我使用的

可以在模式级别强制两个具有不同名称的属性的唯一值

<xs:complexType name="exampleType">
  <xs:attribute name="first" type="xs:integer" use="required"/>
  <xs:attribute name="second" type="xs:integer"/>
</xs:complexType>

如果
first
是1,
second
需要是其他值


编辑:我使用的是xsd 1.0。

正如我在评论中所说,只有当
第一个
第二个
是元素(而不是属性)时,这才有效。
|
xpath操作符它就像节点的并集

<xs:element name="exampleElement" type="exampleType">
    <xs:unique name="firstAndSecondDifferent">
        <xs:selector xpath="first | second" />
        <xs:field xpath="." />
    </xs:unique>
</xs:element>

<xs:complexType name="exampleType">
    <xs:sequence>
        <xs:element name="first" type="xs:integer" />
        <xs:element name="second" type="xs:integer" minOccurs="0" />
    </xs:sequence>
</xs:complexType>
以下元素有效(不存在第二个
元素):


这不能通过属性来完成,因为
选择器xpath
不允许使用属性,所以
“@first |@second”
它不是选择器xpath属性的有效值。

您使用的是哪个XML模式版本?如果您使用的是1.1,您可以只在复杂类型中添加一个子项
。如果
first
second
是元素而不是属性,您可以使用
unique
来做您想做的事情,但我不知道如何使用属性来做。请使用元素而不是属性发布您的答案,但是元素的名称需要保持不同谢谢,我不知道xpath |运算符,我将尝试使用元素重新设计它
<exampleElement>
    <first>1</first>
    <second>5</second>
</exampleElement>
<exampleElement>
    <first>1</first>
</exampleElement>
<exampleElement>
    <first>1</first>
    <second>1</second>
</exampleElement>