0

あちこちで何度か尋ねられましたが、いくつかの回答は古い VS バージョンに関連しています (これは VS 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>

注意 - AlphaNumeric には位置要素があり、ビットマップとアークの両方に AlphaNumeric があります。

(XSD ツールを使用して) cs クラスを作成し、それをインスタンス化しようとすると、次のエラーが発生します。

同じテーブル 'AlphaNumericLocation' は、2 つのネストされたリレーションの子テーブルになることはできません。

この問題を解決するにはどうすればよいですか? (実際の xsd はもっと複雑で、「関連する類似」の子がもっとたくさんあります.....

型指定されたデータセット (xml を簡単に読み取って解析できる) で、アプリの xml データを使用したいと考えています。テーブルと列を他のコントロールに簡単にバインドできます...(グリッド)

4

2 に答える 2

2

Microsoft の XML パーサーはこれをサポートしていません。VS の初期のバージョンから変更されていないと思います。

代わりに何をすべきかについてのヒントについては、こちらを確認してください。 -the-child-table-in-two-nested-relations

于 2013-07-29T14:56:33.600 に答える
1

この問題の回避策を投稿しました。明らかに、それはすべての人にとっての解決策ではないかもしれませんが、少なくとも問題の原因を説明し、問題のあるコードを指摘します.

WriteXML メソッド使用時のシリアル化の問題

また、スキーマで「ネスト」を使用する必要があります。これにより、問題が解決されます。

あなたのスキーマを適応させるのに問題があるので、自分で試してみる必要がありますが、私は自分のスキーマを適応させました。これは、MyRootTable が「PremiumPerYear」とのネストされた関係を持つ 2 つのテーブルを持つ DataSet です。

このネストされたリレーションのキー プレイヤーは<xs:choice element. これにより、スキーマがそれ自体の別の部分を参照できるようになります (私は信じています)。この参照は、「ref」キーワードによって作成/使用されます。 <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>

于 2015-04-08T15:18:32.317 に答える