2013-07-29 68 views
0

幾個時間已經問及這裏和那裏,一些答案與舊版本VS(這是使用V.S. 2012)有關。相同的表'名稱'不能在兩個嵌套關係中的子表

我再次提出這個問題:

給出一個xsd:

<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 

    <xs:complexType name="LocationType"> 
     <xs:attribute name="X" type="xs:integer" /> 
     <xs:attribute name="Y" type="xs:integer" /> 
    </xs:complexType> 

    <xs:complexType name="AlphaNumericType"> 
     <xs:sequence> 
      <xs:element name="AlphaNumericLocation" type="LocationType" /> 
     </xs:sequence> 
     <xs:attribute name="id" type="xs:string" /> 
     <xs:attribute name="key" type="xs:integer" /> 
    </xs:complexType> 

<xs:complexType name="BitmapType"> 
      <xs:sequence> 
       <xs:element name="BitmapLocation" type="LocationType" /> 
       <xs:element name="BitmapCaptions" type="AlphaNumericType" /> 
      </xs:sequence> 
      <xs:attribute name="key" type="xs:string" /> 
      <xs:attribute name="id" type="xs:string" /> 
     </xs:complexType> 

    <xs:complexType name="ArcType"> 
      <xs:sequence> 
       <xs:element name="ArcLocation" type="LocationType" /> 
       <xs:element name="ArcCaptions" type="AlphaNumericType" /> 
      </xs:sequence> 
      <xs:attribute name="key" type="xs:string" /> 
      <xs:attribute name="id" type="xs:string" /> 
     </xs:complexType> 


    <xs:element name="BitmapControls"> 
     <xs:complexType> 
      <xs:sequence minOccurs="0" maxOccurs="unbounded"> 
       <xs:element name="Bitmap" type="BitmapType" /> 
      </xs:sequence> 
     </xs:complexType> 
    </xs:element> 

    <xs:element name="ArcControls"> 
     <xs:complexType> 
      <xs:sequence minOccurs="0" maxOccurs="unbounded"> 
       <xs:element name="Arc" type="ArcType" /> 
      </xs:sequence> 
     </xs:complexType> 
    </xs:element> 
</xs:schema> 

通知 - 即具有杬的位置元素,位圖和弧的字母數字字符。

當我創建(使用XSD工具)的CS類和嘗試實例化它,我得到這個錯誤:

The same table 'AlphaNumericLocation' cannot be the child table in two nested relations.

我怎樣才能解決這個問題? (真正的xsd更復雜,並有更多「相似的類似」兒童.....

我想在我的應用程序中使用類型化數據集中的xml數據(它可以輕鬆讀取和解析xml) 。 ,我可以很容易地綁定表和列到其他控件...(網格)

回答

1

我已經發布了一個工作爲這個問題喋喋不休。 很明顯,它可能不是每個人的解決方案,但至少它解釋了問題的根源,並指出了有問題的代碼。

Serialization Issue when using WriteXML method

此外,你應該在你的模式中使用「築巢」,這將解決這個問題。

我在修改自己的模式時遇到了問題,所以你必須嘗試自己,但我已經適應了我自己的模式。它是一個帶有兩個表的DataSet,其中MyRootTable與'PremiumPerYear'具有嵌套關係。

這個嵌套關係中的關鍵球員是<xs:choice element。它允許(我相信)模式引用自身的另一部分。然後 此引用創建/由「裁判」關鍵字使用: <xs:element ref="PremiumPerYear" />

注:這個例子不具有實際的「雙重嵌套」的關係,但是這只是因爲我切的文字90KB出來。 <DataSet> <xs:schema id="NewDataSet" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:msprop="urn:schemas-microsoft-com:xml-msprop"> <xs:element name="PremiumPerYear"> <xs:complexType> <xs:sequence> <xs:element name="BeforeTaxes" type="xs:decimal" minOccurs="0" /> <xs:element name="AfterTaxes" type="xs:decimal" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true"> <xs:complexType> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element ref="PremiumPerYear" /> <xs:element name="MyRootTable"> <xs:complexType> <xs:sequence> <xs:element name="RequestType" msprop:KeyValueCategory="KindOfRequest" type="xs:string" minOccurs="0" /> <xs:element name="RequestDateTime" type="xs:dateTime" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element> </xs:choice> </xs:complexType> </xs:element> </xs:schema> </DataSet>

相關問題