XSD 元素如何组合成 xsd:extension 模式

How are XSD elements combined in an xsd:extension pattern

我正在努力将 XSD 转换为 FrameMaker EDD,但我卡在了 xsd:extension 机制上。由于 XSD 标准的 W3C 描述非常复杂,我希望这里的一位 XSD 专家能给我一些提示。

这里是我原文中的两个定义XSD:

<xsd:complexType name="basehierarchy">
   <xsd:choice minOccurs="0" maxOccurs="unbounded">
     <xsd:element ref="num"/>
     <xsd:element ref="heading"/>
     <xsd:element ref="subheading"/>
   </xsd:choice>
</xsd:complexType>

<xsd:complexType name="docContainerType">
  <xsd:complexContent>
    <xsd:extension base="basehierarchy">
      <xsd:choice>
        <xsd:element ref="interstitial"/>
        <xsd:element ref="toc"/>
        <xsd:element ref="documentRef"/>
      </xsd:choice>
    </xsd:extension>
  </xsd:complexContent>
</xsd:complexType>

我需要在创建我的 EDD(和随附的 DTD)之前解决扩展问题,但我不确定上述模式应该产生什么结果。我可以想象各种选择 - 一种是注入扩展进基地的选择:

<xsd:complexType name="docContainerType">
  <xsd:choice minOccurs="0" maxOccurs="unbounded">
     <xsd:element ref="num"/>
     <xsd:element ref="heading"/>
     <xsd:element ref="subheading"/>
     <xsd:element ref="interstitial"/>
     <xsd:element ref="toc"/>
     <xsd:element ref="documentRef"/>       
  </xsd:choice>
</xsd:complexType>

作为副作用,这会导致将@minOccurs 和@maxOccurs 应用于扩展模式的元素。也许没关系,但我找不到关于此的明确信息。正确扩展基本模式的另一种选择是在选择基本模式后添加来自扩展的选择:

<xsd:complexType name="docContainerType">
  <xsd:sequence>
    <xsd:choice minOccurs="0" maxOccurs="unbounded">
      <xsd:element ref="num"/>
      <xsd:element ref="heading"/>
      <xsd:element ref="subheading"/>
    </xsd:choice>
    <xsd:choice>
      <xsd:element ref="interstitial"/>
      <xsd:element ref="toc"/>
      <xsd:element ref="documentRef"/>       
    </xsd:choice>
  </xsd:sequence>
</xsd:complexType>

如果第二个选项是正确的,扩展应该在基本元素之前还是之后?

也许推荐可以给你一个线索:XML Schema Part 0: Primer Second Edition, §4.2 Deriving Types by Extension,尤其是这部分文字:

When a complex type is derived by extension, its effective content model is the content model of the base type plus the content model specified in the type derivation. Furthermore, the two content models are treated as two children of a sequential group.