By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,671 Members | 1,393 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,671 IT Pros & Developers. It's quick & easy.

Populate and Merge DataSet to form an XML

P: n/a
Hi,

I need to populate and merge DataSet to make an XML in the following format:

<?xml version="1.0" standalone="yes"?>
<CompanyOrders>
<CompanyProfile>
<CompanyID>Test</CompanyID>
<CompanyName>The Company</CompanyName>
</CompanyProfile>
<OrderInformation>
<BuyerInformation>
<OrderNo>00001</OrderNo>
</BuyerInformation>
</OrderInformation>
</CompanyOrders>

So far I am able to come up with this code:

DataSet dsCompanyOrders = new DataSet("CompanyOrders");
DataTable dt = dsCompanyOrders.Tables.Add("CompanyProfile");
DataColumn dcCompanyID = new DataColumn("CompanyID");
DataColumn dcCompanyName = new DataColumn("CompanyName");
dt.Columns.AddRange(new DataColumn[]
{
dcCompanyID,dcCompanyName
}
);
DataRow drCompanyProfile = dt.NewRow();
drCompanyProfile["CompanyID"] = "Test";
drCompanyProfile["CompanyName"] = "The Company";
dt.Rows.Add(drCompanyProfile);

DataSet dsOrderInformation = new DataSet("OrderInformation");
DataTable dtBuyerInformation =
dsOrderInformation.Tables.Add("BuyerInformation");
DataColumn dcOrderNo = new DataColumn("OrderNo");
dtBuyerInformation.Columns.Add(dcOrderNo);
DataRow drOrderInformation = dtBuyerInformation.NewRow();
drOrderInformation["OrderNO"] = "00001";
dtBuyerInformation.Rows.Add(drOrderInformation);
dsCompanyOrders.Merge(dsOrderInformation,false,Mis singSchemaAction.Add);

dsCompanyOrders.WriteXml("c:\\test.xml",XmlWriteMo de.IgnoreSchema);

The problem is that I cant create the parent node <OrderInformation> and the
XML that is created is as follows:

<?xml version="1.0" standalone="yes"?>
<CompanyOrders>
<CompanyProfile>
<CompanyID>Test</CompanyID>
<CompanyName>The Company</CompanyName>
</CompanyProfile>
<BuyerInformation>
<OrderNo>00001</OrderNo>
</BuyerInformation>
</CompanyOrders>

Need some help with this :S

Thanks, Nauman.
Nov 16 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.