DataSet.ReadXMLSchema question

I have an xsd that needs to be populated with output data for the customer. The initial idea was to read the xsd using XMLDataDocument.DataSet.ReadXMLSchema call to have the .NET create a dataset, then populate it with the data and save into an xml file.

The ReadXMLSchema seems to create one table in the dataset per each element in the schema and name the table after the element's name. However, the schema reuses multiple complex types in several places. As a result, when .NET tries to create a table with the same name, an exception occurs.

Since it's a pretty standard design for an xsd I'm very surprised it doesn't work. Is there any workaround

Here's a simplified example of the xsd I use:

< xml version="1.0" encoding="UTF-8" >
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0">
        <xs:complexType name="Address" abstract="false">
                <xs:sequence>
                        <xs:element name="street" maxOccurs="2">
                                <xs:complexType>
                                        <xs:simpleContent>
                                                <xs:extension base="xs:string">
                                                        <xs:attribute name="ordinal" type="xs:integer" use="optional"/>
                                                </xs:extension>
                                        </xs:simpleContent>
                                </xs:complexType>
                        </xs:element>
                        <xs:element name="state" type="State"/>
                </xs:sequence>
                <xs:attribute name="city" use="optional">
                        <xs:simpleType>
                                <xs:restriction base="xs:string">
                                        <xs:maxLength value="30"/>
                                </xs:restriction>
                        </xs:simpleType>
                </xs:attribute>
                <xs:attribute name="postalCode" type="xs:string" use="optional"/>
        </xs:complexType>
        <xs:complexType name="EntityBase"/>
        <xs:element name="example">
                <xs:complexType>
                        <xs:sequence>
                                <xs:element name="claim" type="Claim"/>
                        </xs:sequence>
                </xs:complexType>
        </xs:element>
        <xs:complexType name="Claim">
                <xs:complexContent>
                        <xs:extension base="EntityBase">
                                <xs:sequence>
                                        <xs:element name="claimant" type="Claimant"/>
                                        <xs:element name="office" type="Office"/>
                                </xs:sequence>
                        </xs:extension>
                </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="Claimant">
                <xs:complexContent>
                        <xs:extension base="EntityBase">
                                <xs:sequence>
                                        <xs:element name="ClaimantAddress" type="Address"/>
                                </xs:sequence>
                        </xs:extension>
                </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="Office">
                <xs:sequence>
                        <xs:element name="address" type="Address"/>
                </xs:sequence>
        </xs:complexType>
        <xs:complexType name="State">
                <xs:attribute name="country" type="xs:string" use="optional"/>
                <xs:attribute name="state" type="xs:string" use="optional"/>
        </xs:complexType>
</xs:schema>


Answer this question

DataSet.ReadXMLSchema question

  • Roberto Jim&amp;#233;nez

    I was able to load this into the Data Set Designer in Visual Studio 2005 and it identified the following tables:

    claim
    claimant
    ClaimantAddress
    street
    state
    office
    address

    So perhaps this issue has been fixed

  • DataSet.ReadXMLSchema question