On 09.12.2011 22:50, CSharp-Jay wrote:
> Demo XML:
>
> <?xml version="1.0" encoding="utf-8" ?>
> <BuildingLayouts>
> <EcoLayouts>
> <Layout>
> <Name>Test EcoLayout</Name>
> <Image>.\images\TestEcoLayout.png</Image>
> </Layout>
> </EcoLayouts>
> <TycoonLayouts>
> <Layout>
> <Name>Test TycoonLayout</Name>
> <Image>.\images\TestTycoonLayout.png</Image>
> </Layout>
> </TycoonLayouts>
> <TechLayouts>
> <Layout>
> <Name>Test TechLayout</Name>
> <Image>.\images\TestTechLayout.png</Image>
> </Layout>
> </TechLayouts>
> </BuildingLayouts>
>
> Code:
>
> DataSet xDS = new DataSet();
> xDS.ReadXml(@".\data\Layouts.xml");
> for (int i = 0; i< xDS.Tables.Count; i++)
> {
> Console.WriteLine(xDS.Tables[i].TableName.ToString());
> }
>
> Console Results:
>
> EcoLayouts
> Layout<--- what?
> TycoonLayouts
> TechLayouts
>
> I have tried this in numerous ways and flavors, completely changing
> the format of the XML every time, yet it keeps counting one of the
> records as a table?
AFAIK if you do not specify any structure information, a table is
created for each XML node type that is not a leaf. But nodes with the
same name in different contexts are unsupported. So it does not create 3
Layout tables but only one.
Create a strongly typed DataSet class with an XSD of your XML structure
and then use ReadXml with that type.
Marcel
|