zooney
zooney

Reputation: 339

Write DataSet to XML file with proper child parent relationships

DataSet newdataSet = new DataSet();       
DataSet dataSet = new DataSet();  
dataSet.ReadXml(readXml);  
newDataSet.Tables.Add(dataSet.Tables["A"].Copy());  
newDataSet.Tables.Add(dataSet.Tables["B"].Copy());  
newDataSet.Tables.Add(dataSet.Tables["C"].Copy());  

Now When i write it to a XMl file ,I want the following output:

<A> <B> <C/> <B/> <B> <C/> <B/> </A>

I have also tried by adding relations among the table by :A->B,B->C

newDataSet.Relations.Add(newDataSet.Tables["A"].Columns["A_Id"],newDataSet.Tables["B"].Columns["A_Id"]);   
newDataSet.Relations.Add(newDataSet.Tables["B"].Columns["B_Id"],newDataSet.Tables["C"].Columns["B_Id"]);

But the output is still:

<A/> <B/> <B/> <c/> <C/> 

Upvotes: 1

Views: 1802

Answers (1)

zooney
zooney

Reputation: 339

Suppose the added Relations were X and Y, You need to set X.Nested=True and Y.Nested=True to get the desired output.

http://msdn.microsoft.com/en-us/library/7sfkwf9s%28v=vs.110%29.aspx

Upvotes: 1

Related Questions