【问题标题】:XSD InheritanceXSD 继承
【发布时间】:2009-12-23 15:17:31
【问题描述】:

我正在寻找一种我不太确定是否可行的 XSD 继承,所以我想确定一下 :)

问题是我有一个复杂类型 A 和另一个复杂类型 B,它与 A 的不同之处在于它的属性具有固定值。

示例:

<xs:complexType name="A">
    <xs:attribute name="AAtrr" type="xs:string"/>
  </xs:complexType>

<xs:complexType name="B">
    <xs:attribute name="AAtrr" type="xs:string" fixed="Something"/>
  </xs:complexType>

这当然是一个简化的例子,但首先我想知道 B 是否可以继承 A 并为属性添加固定值。

【问题讨论】:

    标签: xml xsd


    【解决方案1】:

    这是一种方法,有一些细节:

    <xs:complexType name="A">
        <xs:attribute name="AAttr" type="xs:string"/>
    </xs:complexType>
    <xs:complexType name="B">
         <xs:complexContent>
             <xs:restriction base="A">
                  <xs:attribute name="AAttr" type="Restricted"/>
             </xs:restriction>
         </xs:complexContent>
    </xs:complexType>
    <xs:simpleType name="Restricted">
        <xs:restriction base="xs:string">
            <xs:enumeration value="Something"/>
        </xs:restriction>
    </xs:simpleType>
    

    【讨论】:

      【解决方案2】:

      在 XSD 中你可以这样做,但 B 不是 A 的扩展,而是 A 的限制。

      【讨论】:

      • 你或其他人能用我的例子来说明具体方法吗?如何限制特定属性?我认为这样的东西是无效的:
      • 查看 xcut 的答案 - 他更快。 :-)
      猜你喜欢
      • 2010-09-17
      • 1970-01-01
      • 1970-01-01
      • 2011-09-15
      • 1970-01-01
      • 1970-01-01
      • 2013-02-03
      • 1970-01-01
      • 2015-04-19
      相关资源
      最近更新 更多