2010-11-24 9 views
3

私はいくつかの他の子タイプの基本タイプであるchange要素タイプのリストを保持する要素タイプを構築しようとしています。 C++コードを生成するCodeSynthesisを使用してXSD:多型 "リスト"の作成方法

<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> 

イム」:私はこのコードを得ました。

ここでは、さまざまなタイプへのアクセスを明確に定義しているので、これは残念です。私が望むのは、もっとシンプルなものだと思います。

変更リスト私は変化の異なるサブタイプのための異なるタグを持ってすることはできません

<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> 

今。 substitution groupを使用するのが良い解決策かもしれないと思いました。

しかし、私は特定のサブタイプの属性と要素を使用する能力が失われてしまいます。

元の解決策はそれを行うのに適していますか(子タイプも取得できる基本タイプのオブジェクトのリストがあります)

+1

? XMLスキーマで多形性をモデル化するのが一般的な方法です。 – lexicore

+0

多分私は間違っていますが、代替グループを使用しているAFAIKはエイリアスのようなものですよね?それから私は "変更"タグのエイリアスとして使うことができます、私は正しいのでしょうか?そして、私はchange-tag-child-element-type-specific要素と属性を使うことができません。私は正しいですか? – Klaim

答えて

0

xml-schemaでは必要なものはありません。定義された型を拡張(または制限)することはできますが、これは新しい型です。サブタイプの多型(包含多型)は、xml-schemaには存在しません。

+0

例えば、シーケンスにある型の要素やこの型の子型を持たせることはできません。それとも、私の問題を解決するのに役立つxsdに相当するものがありますか? – Klaim

0

これは変更の一覧ですが、リストに記録されている変更の種類(有効化、切り替えなど)も必要です。

私は、データ型が別の要素、ChangeTypeType、有効な変更された型の列挙型になる "type"属性を持つChangeType要素と呼ばれる単純な要素を作成します。例えば:のような

<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> 
+0

私はすでにそれを持っていますが、それは問題を解決しません。そうした場合、子要素タイプ固有のコンテンツにアクセスすることはできません。たとえば、スイッチにのみ "target"要素(または属性)がある場合、リストに設定することはできません。 – Klaim

3

あなたはまだ答えが必要な場合はいけない知っている...しかし、次のスキーマは、何が必要ありません。

すべてのベース型の第1および2つのコンクリートのサブタイプ(あなたのベースクラスは抽象=「true」のセットを持っていることを、確認してください):次にBaseTaskのサブタイプである要素を保持しているリストを追加

<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> 

<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> 
関連する問題