Schema-Typed Dataset doesn't preserve nested tables order

S

sunstormlabs

Hello,

I'm having trouble with schema-bound XML output from a dataset,
in .NET 2.0. Here's an example bit of XML I'm trying to create using a
dataset:

<TestSchema xmlns="http://tempuri.org/TestSchema.xsd">
<Customer>
<Name>Mr. Foo</Name>
<Company>Foo Inc.</Company>
<BillingAddress>
<BuildingNumber>123</BuildingNumber>
<StreetName>Street Name</StreetName>
<City>City</City>
</BillingAddress>
<Telephone>123456789</Telephone>
</Customer>
</TestSchema>

Note that BillingAddress goes before Telephone.

I'm using the following schema, which I have no control over, and so
can't change, to generate the dataset using VS2008's dataset
generator:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="TestSchema" targetNamespace="http://tempuri.org/
TestSchema.xsd" elementFormDefault="qualified" xmlns="http://
tempuri.org/TestSchema.xsd" xmlns:mstns="http://tempuri.org/
TestSchema.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name='Name' type='xs:string' />
<xs:element name='Company' type='xs:string' />
<xs:element name='Telephone' type='xs:string' />

<xs:element name='BuildingNumber' type='xs:string' />
<xs:element name='City' type='xs:string' />
<xs:element name='StreetName' type='xs:string' />

<xs:complexType name='AddressStructure'>
<xs:sequence>
<xs:element ref='BuildingNumber' minOccurs='0' />
<xs:element ref='StreetName' minOccurs='0' />
<xs:element ref='City' />
</xs:sequence>
</xs:complexType>

<xs:element name='BillingAddress' type='AddressStructure' />

<xs:element name='Customer'>
<xs:complexType>
<xs:sequence>
<xs:element ref='Name' />
<xs:element ref='Company' />
<xs:element ref='BillingAddress' />
<xs:element ref='Telephone' />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

It works just fine, the dataset generator creates the keys and
relationships to nest the BillingAddress table, and I can fill in the
data I need into the dataset like so...

TestSchema set = new TestSchema();
TestSchema.CustomerRow customerRow =
set.Customer.AddCustomerRow( "Mr.Foo", "Foo Inc.", "123456789" );
set.BillingAddress.AddBillingAddressRow( "123", "Street Name", "City",
customerRow );

However, the output I get is...

<TestSchema xmlns="http://tempuri.org/TestSchema.xsd">
<Customer>
<Name>Mr.Foo</Name>
<Company>Foo Inc.</Company>
<Telephone>123456789</Telephone>
<BillingAddress>
<BuildingNumber>123</BuildingNumber>
<StreetName>Street Name</StreetName>
<City>City</City>
</BillingAddress>
</Customer>
</TestSchema>

Note how BillingAddress has moved to the end, effectively making the
XML non-compliant to the schema. I can't see any reason why would the
dataset willingly break it's own schema.

Any idea how to get around this strange behavior?
 
V

varsha.dhankani

Hey

Did you find a solution to the above problem?
I'm stuck with the same..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top