2015-10-16 22 views
0

我需要避免mixed =「true」,因爲如果我在我的* .XSD文件中使用mixed =「true」,那麼我的Microsoft SSIS會抱怨。我收到以下錯誤信息:xsd - 如何避免混合=「真」有什麼選擇?

「...... XML源適配器不支持混合內容的複雜類型的模型」

我的XML的文件:

<MappingProject name="anyString1"> 
    <MappingSpecification name="anyString2"> 
     <MappingTargetTable>TEXT_BLOCK1</MappingTargetTable> 
     <MappingSourceTables> 
      <Table>TEXT_BLOCK2</Table> 
      <Table>TEXT_BLOCK3</Table> 
     </MappingSourceTables> 
     <Description> 
      <DescriptionText>Some Text... </DescriptionText> 
      <Condition type="filter"> -</Condition> 
     </Description> 
    </MappingSpecification> 
    </MappingProject> 

我的XSD的文件:

<!-- <MappingProject> --> 
<xs:element name="MappingProject"> 
    <xs:complexType> 
     <xs:sequence> 
      <xs:element name="MappingSpecification" type="MappingSpecificationType"/> 
     </xs:sequence> 
    <xs:attribute name="name" type="xs:string" use="required"/> 
    </xs:complexType> 
</xs:element> 

<!-- MappingSpecification --> 
<xs:complexType name="MappingSpecificationType"> 
    <xs:sequence> 
     <xs:element name="MappingTargetTable" minOccurs="0" maxOccurs="unbounded"/> 
     <xs:element name="MappingSourceTables" minOccurs="0" maxOccurs="unbounded"/> 
     <xs:element name="Description" type="DescriptionType" minOccurs="1"/> 
    </xs:sequence> 
    <xs:attribute name="name" type="xs:string" use="required"/> 
</xs:complexType> 

<!-- Description --> 
<xs:complexType name="DescriptionType"> 
    <xs:sequence> 
     <xs:element name="DescriptionText"/> 
     <xs:element name="Condition" type="ConditionType"/> 
    </xs:sequence> 
</xs:complexType> 

<!-- Condition--> 
<xs:complexType name="ConditionType" mixed="true"> 
    <xs:attribute name="type" type="xs:string" use="required"/> 
</xs:complexType> 

此部分:xs:complexType name="ConditionType" mixed="true"是必要的,因爲否則我得到這樣的錯誤信息:

「元素‘條件’不能有性格[兒童],因爲該類型的內容類型是 元素,只有」

現在是什麼?我不能使用mixed="true",因爲MS SSIS不喜歡它,但否則會出現錯誤。你能幫我嗎?

非常感謝!

回答

1

如果元素分別鍵入應該沒有子元素,但至少一個屬性值,那麼你應該把它定義爲

<xs:complexType name="ConditionType"> 
      <xs:simpleContent> 
      <xs:extension base="string"> 
       <xs:attribute name="type" type="xs:string" use="required"/> 
      </extension> 
      </xs:simpleContent> 
</xs:complexType> 
+0

yey,謝謝:)它工作得很好! –

+0

但還有一個問題,如果這是可能的話......我該如何擴展它?可能還有一個在上面? –

+0

您爲該元素顯示的示例XML是' -',它沒有任何子元素。您還有其他類型,例如'MappingSpecificationType',您可以在其中知道如何使用屬性和子元素定義複雜類型。所以如果你想要' foo bar'那麼我想你知道該怎麼做。如果你真的需要將文本內容與元素內容混合,那麼你需要'mixed =「true」',但聽起來好像你的目標系統不支持。 –