ADO.NET and XML Schemas: Generating the XML using the DataSet

ADO.NET and XML Schemas: Generating the XML using the DataSet

Post by TmF1bWFuIE » Sat, 05 Mar 2005 06:59:03


Hi,

I have to prepare a XML file in the following format:

<CompanyOrders>
<CompanyProfile>
<CompanyID>Test</CompanyID>
<CompanyName>The Company</CompanyName>
</CompanyProfile>
<OrderInformation>
<BuyerInformation>
<OrderNo>00001</OrderNo>
<FName>John</FName>
<LName>Doe</LName>
</BuyerInformation>
<CustomerEMailInformation>
<EmailAddr> XXXX@XXXXX.COM </EmailAddr>
<CustomerEMailInformation>
<CreditCardInformation>
<CcType>MA</CcType>
<ExpYear>09</ExpYear>
</CreditCardInformation>
</OrderInformation>

This information will come from one table CustomerOrder. Here are my
questions:

1. I suspect I will have to create multiple data adapter as
<CustomerEMailInformation> exist outside the <BuyerInformation>.
2. The code that I have written untile now:

DataSet dsOrders = new DataSet("CompanyOrders");
this.dsOrders.Tables.Clear();
SqlDataAdapter sdaOrder = new SqlDataAdapter(this.strSQL,conn);
sdaOrder.Fill(this.dsOrders,"OrderInformation");
conn.Close();
this.dsOrders.WriteXml("C:\\test.xml",XmlWriteMode.IgnoreSchema);

And the XML output is as follows:

<CompanyOrders>
<OrderInformation>
<OrderNo>I000004</OrderNo>
<FName>Nauman</FName>
<MI />
<LName>Ahmed</LName>
<CoName>Company</CoName>
<Street>Address</Street>
<City>City</City>
<State>State</State>
<ZipCode>Zip</ZipCode>
<CountryCode>1000</CountryCode>
<DayPhone>000-000-0000</DayPhone>
</OrderInformation>
</CompanyOrders>

I need the information contained in the
<OrderInformation></OrderInformation> tags to be contained in
<BuyerInformation></BuyerInformation> tags as it is defined in the DTD. Any
suggestions?

Thanks, Nauman.