首页 > 解决方案 > 如何知道应该使用 C++ 中的适配器定义哪个 XSD 元素?

问题描述

 <xsd:complexType name="Parallel">
    <xsd:complexContent>
      <xsd:extension base="otx:CompoundNode">
        <xsd:sequence>
          <xsd:element name="realisation" type="otx:ParallelRealisation" minOccurs="0" maxOccurs="1"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>

只需像上面那样发布一个 XSD 片段,我正在尝试将其生成为 C++ 代码,我必须定义一个用于描述 CompoundNode 类型的类,同时也是一个描述 Parallel 类型的类。而实际上,Parallel 类型的实例是这样的:

<CompoundNode xsi:type="Parallel">

...

在 C++ 代码中,我应该设计另一个类作为适配器,将基类 CompoundNode 转移到指定的子类(在我的 xsd 文件中确实有很多从 CompoundNode 派生的类),当然你可以说这只是多态性。

我的问题:当我不知道应该使用适配器类设计哪个基类时,XSD 架构中的规则是什么。

标签: c++xmlxsd

解决方案


推荐阅读