首页 > 解决方案 > 这个 XSD 限制是什么意思。具有限制的派生类型只是基类型的一个属性

问题描述

有一个基本类型“Objectnummering-e”和一个派生类型“ObjectNummering-geoBAG”。“ObjectNummering-geoBAG”的限制提到了基本类型的属性。

我不清楚这是做什么的。对我来说,这两种类型是相同的。但他们是吗?

<complexType name="ObjectNummering-geoBAG">
   <simpleContent>
      <restriction base="BG:ObjectNummering-e">
         <attribute ref="StUF:noValue"/>
       </restriction>
   </simpleContent>
</complexType>


<complexType name="ObjectNummering-e">
   <simpleContent>
      <extension base="BG:ObjectNummering">
         <attributeGroup ref="StUF:element"/>
      </extension>
   </simpleContent>
</complexType>


<simpleType name="ObjectNummering">
    <restriction base="string">
       <length value="16"/>
    </restriction>
</simpleType>

<attributeGroup name="element">
    <attribute ref="StUF:noValue"/>
    <attribute ref="StUF:exact"/>
 </attributeGroup>

标签: xsd

解决方案


与往常一样,回答此类问题的唯一可靠方法是查看 W3C 规范。您的复杂类型是“具有简单内容的复杂类型”,因此相关部分是:

https://www.w3.org/TR/xmlschema-1/#declare-type,小节Complex Type Definition with simple content Schema Component

3 如果由基[属性]的·实际值·解析的类型定义是一个复杂类型定义,则该类型定义的{属性使用},除非选择了替代方案,在这种情况下,该类型定义的某些成员类型定义的 {attribute uses} 可能不包括在内,即那些 {attribute declaration} 的 {name} 和 {target namespace} 与以下之一相同: 3.1 {name} 和 {target namespace}属性声明} 在上面第 1 条或第 2 条的集合中使用的属性;3.2 属性声明的{name}和{target namespace}会是什么儿童]被禁止。

用简单的英语来说,这意味着一个复杂的类型限制必须重新声明它想要保留的任何属性——它们不会自动继承。所以派生类型“ObjectNummering-geoBAG”只有 1 个属性,而不是 2 个。


推荐阅读