3

change他のいくつかの子型の基本型である要素型のリストを保持する要素型を構築しようとしています。私はこのコードを得ました:

<xs:complexType name="change_list" >
    <xs:annotation>
      <xs:documentation>List of changes.</xs:documentation>
    </xs:annotation>

    <xs:sequence>
      <xs:choice minOccurs="1" maxOccurs="unbounded" >

        <xs:element name="change" type="aos:change" >
          <xs:annotation>
            <xs:documentation>Generic or specific type of change.</xs:documentation>
          </xs:annotation>
        </xs:element>

        <xs:element name="activate" type="aos:activate" >
          <xs:annotation>
            <xs:documentation>Change that will activate an element or do nothing if already activated.</xs:documentation>
          </xs:annotation>
        </xs:element>

        <xs:element name="deactivate" type="aos:deactivate" >
          <xs:annotation>
            <xs:documentation>Change that will deactivate an element or do nothing if already deactivated.</xs:documentation>
          </xs:annotation>
        </xs:element>

        <xs:element name="switch" type="aos:switch" >
          <xs:annotation>
            <xs:documentation>Change that will activate the element if deactivated or deactivate it if activated.</xs:documentation>
          </xs:annotation>
        </xs:element>

        <xs:element name="transform" type="aos:transform" >
          <xs:annotation>
            <xs:documentation>
              Change that will modify the geometric state of the element
              by applying one or several geometric transformations.
            </xs:documentation>
          </xs:annotation>
        </xs:element>


      </xs:choice>
    </xs:sequence>

CodeSynthesis を使用して C++ コードを生成しています。

ここでは、さまざまな型へのアクセスを明確に定義しているため、これはやり過ぎに思えます。私が欲しいのは、次のようなもっと単純なものだと思います:

変更のリスト。

    <xs:sequence>
      <xs:choice minOccurs="1" maxOccurs="unbounded" >

        <xs:element name="change" type="aos:change" >
          <xs:annotation>
            <xs:documentation>Generic or specific type of change.</xs:documentation>
          </xs:annotation>
        </xs:element>

      </xs:choice>
    </xs:sequence>

これで、変更のサブタイプごとに異なるタグを付けることができなくなりました。だから私は多分良い解決策は置換グループを使うことだと思った.

しかし、そうすると、特定のサブタイプの属性と要素を使用できなくなります。

元の解決策はそれを行うのに適していますか(子型も取得できる基本型オブジェクトのリストを持っています)?

4

3 に答える 3

3

まだ答えが必要かどうかはわかりません...しかし、次のスキーマは必要なことを行います。

まず、基本型と 2 つの具体的なサブタイプ (基本クラスに abstract="true" が設定されていることを確認してください):

<xs:complexType abstract="true" name="BaseTask">
  <xs:sequence>
    <xs:element name="Name" type="xs:string" />
  </xs:sequence>
</xs:complexType>

<xs:complexType name="ConcreteTask1">
  <xs:complexContent>
    <xs:extension base="BaseTask">

    </xs:extension>
  </xs:complexContent>
</xs:complexType>

<xs:complexType name="ConcreteTask2">
  <xs:complexContent>
    <xs:extension base="BaseTask">
      <xs:sequence>
        <xs:element name="Description" type="xs:string" />
      </xs:sequence>
    </xs:extension>
  </xs:complexContent>
</xs:complexType>

次に、BaseTask のサブタイプである要素を保持するリストを追加します。

<xs:element name="TaskList">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="Tasks" minOccurs="0" maxOccurs="unbounded" type="BaseTask" />
    </xs:sequence>
  </xs:complexType>
</xs:element>

xml は次のようになります。

<TaskList>
  <Tasks xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ConcreteTask1">
    <Name>Foo1</Name>
  </Tasks>
  <Tasks xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ConcreteTask2">
    <Name>Foo2</Name>
    <Description>Test</Description>
  </Tasks>
</TaskList>
于 2011-11-30T10:56:26.100 に答える
0

あなたが望むことはxml-schemaでは不可能です。定義済みの型を拡張 (または制限) できますが、これは新しい型です。サブタイピング ポリモーフィズム (包含ポリモーフィズム) は xml-schema には存在しません。

于 2010-12-04T21:24:49.320 に答える
0

必要なのは変更のリストのようですが、リストに記録された変更の種類 (アクティブ化、切り替えなど) も必要です。

私がすることは、データ型が別の要素になる「タイプ」属性を持つChangeType要素と呼ばれる単純な要素を作成することです.ChangeTypeTypeは、有効な変更された型の列挙型になります. 例えば:

<element name="ChangeList" type="ChangeListType"/>    
<complexType name="ChangeListType">
    <annotation>
        <documentation>
            A list of changes
        </documentation>
    </annotation>
    <sequence>
        <element name="change" type="ChangeType" minOccurs="1" maxOccurs="unbounded">
            <annotation>
                <documentation>
                    A change event
                </documentation>
            </annotation>
        </element>
    </sequence>
</complexType>

<complexType name="ChangeType">
    <annotation>
        <documentation>
            A change unit
        </documentation>
    </annotation>
    <attribute ref="typeOfChange" use="required"/>
</complexType>

<attribute name="typeOfChange" type="ChangeTypeType">
    <annotation>
        <documentation>
            The kind of change
        </documentation>
    </annotation>
</attribute>

<simpleType name="ChangeTypeType">
    <annotation>
        <documentation>
            Describes the types of allowed changes
        </documentation>
    </annotation>
    <restriction base="token">
        <enumeration value="activate"/>
        <enumeration value="activate"/>
                    <enumeration value="switch"/>
                    <enumeration value="transform"/>
    </restriction>
</simpleType>

これにより、次のような XML ドキュメントが得られます。

<ChangeList>
    <change typeOfChange="activate/>
    <change typeOfChange="switch/>
    <change typeOfChange="transform/>
</ChangeList>
于 2010-12-06T22:55:16.770 に答える