【问题标题】:How to rename a attribute from a inherited type in XSD?如何从 XSD 中的继承类型重命名属性?
【发布时间】:2014-02-27 19:55:12
【问题描述】:
<xs:complexType name="country">
  ...
  <xs:attribute name="zipcode" type="xs:string"/>
  ...
</xs:complexType>

<xs:complexType name="city">
  <xs:complexContent>
    <xs:extension base="country">
      <xs:attributeRename from="zipcode" to="areaCode"/><!-- How to rename? -->
    </xs:extension>
  </xs:complexContent>
</xs:complexType>

我的“城市”类型源自“国家”。我希望在派生后重命名属性。所以我的 2 个 XML 对象都是有效的。当然,我知道我不能使用继承。但是它们还有 10 多个其他属性,我不希望有任何重复。

<country areacode="123"></country>
<city zipcode="456"></city>

【问题讨论】:

    标签: xsd xsd-validation


    【解决方案1】:

    如果从上下文的角度来看,一个城市不应该继承一个国家。

    但是,它们都可以继承 location 类型,该类型具有所有共享属性和字段,citycountry 可以扩展 location 以供自己使用。

    据我所知,没有办法从您扩展的类型中重命名或删除属性或字段。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-15
      • 2015-01-17
      • 1970-01-01
      • 2020-11-16
      • 1970-01-01
      • 2014-10-06
      • 2016-02-15
      相关资源
      最近更新 更多