I was given an .xml file that I needed to read into my code as a DataSet (as background, the file was created by creating a DataSet in C# and calling dataSet.WriteXml(file, XmlWriteMode.IgnoreSchema), but this was done by someone else).
The .xml file was shaped like this:
<?xml version='1.0' standalone='yes'?> <NewDataSet> <Foo> <Bar>abcd</Bar> <Foo>efg</Foo> </Foo> <Foo> <Bar>hijk</Bar> <Foo>lmn</Foo> </Foo> </NewDataSet>
Using C# and .NET 2.0, I read the file in using the code below:
DataSet ds = new DataSet(); ds.ReadXml(file);
Using a breakpoint, after this line ds.Tables[0] looked like this (using dashes in place of underscores that I couldn’t get to format properly):
Bar Foo-Id Foo-Id-0 abcd 0 null null 1 0 hijk 2 null null 3 2
I have found a workaround (I know there are many) and have been able to successfully read in the .xml, but what I would like to understand why ds.ReadXml(file) performed in this manner, so I will be able to avoid the issue in the future. Thanks.
This appears to be correct for your nested Foo tags:
So this correctly becomes 4 records in your result, with a parent-child key of ‘Foo-Id-0’
Try:
Which should result in: