XSD - 需要2个属性中的一个?

use*_*454 57 xsd

有没有办法指定XSD中需要2个属性中的一个?

例如,我有这样的定义:

<xs:attribute name="Name" type="xs:string" use="optional" />
<xs:attribute name="Id" type="xs:string" use="optional" />
Run Code Online (Sandbox Code Playgroud)

我希望能够定义至少需要其中一个.那可能吗?

mar*_*c_s 42

不,我认为你不能用属性做到这一点.你可以将两个包装<xs:element>成一个<xs:choice>- 但是对于属性,没有相应的结构,我担心.


jer*_*ahn 23

XSD 1.1将允许您使用断言执行此操作.

<xsd:element name="remove">
    <xsd:complexType>                        
        <xsd:attribute name="ref" use="optional"/>
        <xsd:attribute name="uri" use="optional"/>
        <xsd:assert test="(@ref and not(@uri)) or (not(@ref) and @uri)"/>            
    </xsd:complexType>
</xsd:element>
Run Code Online (Sandbox Code Playgroud)

  • 我不相信 xsl 'or' 是排他的。我们希望它是其中之一,但不是两者兼而有之。 (4认同)

Cer*_*rus 9

Marc非常正确......你不能在XSD中的xs:choice父元素中使用xs:属性子元素.

逻辑似乎是,如果元素的两个实例具有互斥的属性集,那么它们在逻辑上是两个不同的元素.

Jeni Tennison 在此提出了解决方法.


Ond*_*něk 5

您应该在W3C wiki上查看这些页面:简单属性含义属性muttex