2010-11-24 5 views
3

다른 여러 하위 유형의 기본 유형 인 change 요소 유형의 목록을 유지하는 요소 유형을 작성하려고합니다. 나는이 코드를 가지고있다 :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> 

Im 'C++ 코드를 생성하기 위해 CodeSynthesis 사용.

자, 여기서 우리는 다른 유형에 대한 액세스를 명확하게 정의하기 때문에 과도한 것처럼 보입니다. 나는 내가 원하는 것이 더 단순한 것 같다고 생각한다.

변경 목록. 나를 변화의 다른 아형에 대해 서로 다른 태그를 허용하지 않는

<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

변경 사항 목록은 원하는 것처럼 들리지만 목록에 기록 된 변경 유형 (활성화, 전환 등)도 필요합니다.

내가하는 것은 데이터 형식이 다른 요소 인 ChangeType 요소가있는 ChangeType 요소라는 간단한 요소를 만드는 것입니다.이 요소는 유효한 변경된 형식의 열거 형이 될 ChangeTypeType입니다. 예를 들면 : 당신은 여전히 ​​대답을해야하는 경우

<ChangeList> 
    <change typeOfChange="activate/> 
    <change typeOfChange="switch/> 
    <change typeOfChange="transform/> 
</ChangeList> 
+0

나는 이미 그 문제를 해결하지 못했지만, 그렇게하면 하위 요소 유형 특정 내용에 액세스 할 수 없습니다. 예를 들어 스위치에만 "대상"요소 (또는 속성)가있는 경우 목록에 설정할 수 없습니다. – Klaim

3

그나마 알고 ...하지만 다음 스키마는 당신이 필요하지 :

<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 문서를 줄 것이다.

모든 기본 유형의

첫 번째와 두 개의 콘크리트 하위 유형 (당신의 기본 클래스는 추상적 = "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> 
관련 문제