0

Several time already asked here and there, some answers relate to old VS versions (this on is using V.S. 2012).

I present the problem again:

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

Notice - that AlphaNumeric has a location element, and both bitmap and arc has AlphaNumeric.

When I create a cs class (using XSD tool) and try to instantiate it I get this error:

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

How can I overcome this issue ? (the real xsd is more complicated and has a lot more "related similar" children.....

I want to use the xml data in my app in a typed dataset (which easily read and parse the xml). and I can easily bind tables and columns to other controls... (grid)

Dani
  • 14,639
  • 11
  • 62
  • 110

2 Answers2

2

Microsoft's XML parser does not support this: I don't think it's changed since early versions of VS.

Check here for some hints on what to do instead: http://social.msdn.microsoft.com/Forums/en-US/22f98352-83b9-4638-a306-34a36a11e4d6/the-same-table-choice-cannot-be-the-child-table-in-two-nested-relations

  • the xml is ok with it. The Dataset version is the problem. I can see the xsd in the designer. I can't use it... – Dani Jul 30 '13 at 02:38
1

I have posted a workaround for this problem. Obviously it may not be a solution for every one, but at least it explains the source of the problem an points a finger to the offending code.

Serialization Issue when using WriteXML method

Also, you should use 'nesting' in your schema, that will fix the problem.

I have problems adapting your schema, so you'll have to try yourself, but I have adapted one of my own. It's a DataSet with two tables, where MyRootTable has a nested relation with 'PremiumPerYear'.

The key player in this nested relation is the <xs:choice element. It allows (I believe) the schema to reference another part of itself. This reference is then created/used by the 'ref' keyword: <xs:element ref="PremiumPerYear" />

Note: this example does not have an actual 'double nested' relation, but that's just because I cut 90kb of text out. <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>

Community
  • 1
  • 1
Kabwla-TwoLips
  • 101
  • 1
  • 6