0

I am creating an xml file using c# dataset.writexml() method. One of my parent tables have two child tables, and I want the xml to display records from both tables together. I added relations in my dataset between Parent table and child tables, but I am not getting the records together. The xml always have all records from Child table 1 together followed by all records from Child table 2.

Is there any way to get record 1 from both tables, followed by record 2 from both tables and so on.

<Parent>
  <Child Table 1 Row 1>
  <Child Table 2 Row 1>
  <Child Table 1 Row 2>
  <Child Table 2 Row 2>
<\parent table>

The sample xml would look like this. This is what the customer is asking for.

<Parent>
  <Count>2</Count> 
  <Child 1>
    <ID>111</ID> 
    <No>11111</No> 
  </Child 1>
  <Child 2>
      <AppNo>11111111</AppNo> 
  </Child 2>
  <Child 1>
    <ID>222</ID> 
    <No>22222</No> 
  </Child 1>
  <Child 2>
      <AppNo>22222222</AppNo> 
  </Child 2>
<\Parent>
  • 1
    You may be able to create a DataView and specify a sorting string, then copy the newly sorted DataView back to a DataTable/DataSet and I would think that should be sorted however you specified in the sorting string. Then you should be able to serialize to Xml using that same method and have it ordered. You would in essence be recreating your whole DataSet, and sorting it how you want, then writing it to Xml. – mservidio May 22 '12 at 18:45

1 Answers1

0

If I understand your question correctly, this isn't even valid xml. Child elements will never be together as you are expecting.

The Child table has to have a closing tag before opening another Child table, unless you want the Child Table 2 to be under Child Table 1.

Do you have a concrete example that could maybe explain the problem a bit more? I don't think it's going to behave as you expect it.

Kyle C
  • 1,627
  • 12
  • 25