代码之家  ›  专栏  ›  技术社区  ›  Dean Thomas

XSD需要两个属性中的一个?

  •  4
  • Dean Thomas  · 技术社区  · 15 年前

    例如,我有这样一个定义:

    <xs:attribute name="Name" type="xs:string" use="optional" />
    <xs:attribute name="Id" type="xs:string" use="optional" />
    

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

    2 回复  |  直到 7 年前
        1
  •  46
  •   Paolo Forgia panoet    6 年前

    不,我认为你不能用属性来做。你可以包两个 <xs:element> 变成一个 <xs:choice> -但对于属性,恐怕没有等价的构造。

        2
  •  27
  •   jeremiah jahn    12 年前

    <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>
    
        3
  •  9
  •   Cerebrus    16 年前

    马克说得很对。。。XSD中xs:choice父元素内不能有xs:attribute子元素。

    Jeni Tennison提出了一个解决方案 here .

        4
  •  5
  •   Ondřej Doněk    13 年前

    您应该查看W3C wiki上的以下页面: Simple attribute implication Attribute muttex

        5
  •  -3
  •   NIthin    10 年前

    该示例定义了一个名为“person”的元素,该元素必须包含“employee”元素或“member”元素。

    <xs:element name="person">
      <xs:complexType>
        <xs:choice>
          <xs:element name="employee" type="employee"/>
          <xs:element name="member" type="member"/>
        </xs:choice>
      </xs:complexType>
    </xs:element>
    
    推荐文章