PC Review


Reply
Thread Tools Rate Thread

DataSet.ReadXML has strange results

 
 
CSharp-Jay
Guest
Posts: n/a
 
      9th Dec 2011
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?
 
Reply With Quote
 
 
 
 
Marcel Müller
Guest
Posts: n/a
 
      11th Dec 2011
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
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:01 AM.