【问题标题】:Options on XSD attributesXSD 属性的选项
【发布时间】:2012-05-16 14:23:00
【问题描述】:

是否可以为 XSD 属性定义选项?我希望元素“where”具有属性“logic”,并且只能具有值“OR”或“AND”。

例子:

<where logic="OR"> <!-- valid -->
    ...
</where>

<where logic="XPTO"> <!-- invalid -->
    ...
</where>

这可能吗?

【问题讨论】:

    标签: xml xsd schema


    【解决方案1】:

    是的,这是可能的。

    首先你要定义一个简单的类型:

    <xs:simpleType name="boolString">
       <xs:restriction base="xs:string">
          <xs:enumeration value="AND"/>
          <xs:enumeration value="OR"/>
       </xs:restriction>
    </xs:simpleType>
    

    然后你必须定义一个where 元素,其中包含logic 类型的boolString 属性:

    <xs:element name="where">
       <xs:complexType>
          <xs:attribute name="logic" type="boolString" />
       </xs:complexType>
    </xs:element>
    

    【讨论】:

      猜你喜欢
      • 2020-06-05
      • 1970-01-01
      • 1970-01-01
      • 2012-04-05
      • 2012-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-09
      相关资源
      最近更新 更多