【问题标题】:XSD : restrict many different attributes that take the same valuesXSD:限制许多具有相同值的不同属性
【发布时间】:2013-09-25 07:30:07
【问题描述】:

我想这样做: XML Schema How to Restrict Attribute by Enumeration

...但是我有许多不同的属性,它们具有完全相同的值。这使我的 XSD 非常复杂。 我可以定义一次限制,然后以某种方式在每个属性上引用它吗???

提前致谢。 :)

【问题讨论】:

    标签: attributes xsd restrict


    【解决方案1】:

    如果您有许多不同的属性具有完全相同的值,只需重用属性类型定义:

    <?xml version="1.0" encoding="utf-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
               version="1.0">
    
      <xs:simpleType name="colorType">
        <xs:restriction base="xs:string">
          <xs:enumeration value="red" />
          <xs:enumeration value="green" />
          <xs:enumeration value="blue" />
        </xs:restriction>
      </xs:simpleType>
    
      <xs:element name="RoomColors">
        <xs:complexType>
          <xs:attribute name="wall" type="colorType"/>
          <xs:attribute name="carpet" type="colorType"/>
          <xs:attribute name="ceiling" type="colorType"/>
          <xs:attribute name="funiture" type="colorType"/>
        </xs:complexType>
      </xs:element>  
    
    </xs:schema>
    

    只有当价值观不完全相同时,才会有更多的创造力。见Extend enumerated lists in XML schema

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-10
      • 1970-01-01
      相关资源
      最近更新 更多