Bug in Dataset.Readxml method? (Framework 2.0)

  • Thread starter Thread starter duane.roelands
  • Start date Start date
D

duane.roelands

Take the following xml file (test.xml):

<SourceData>
<Transaction>
<ID>11</ID>
<Transaction>Insurance Loan Addon</Transaction>
<TransactionAmount>31.21</TransactionAmount>
</Transaction>
</SourceData>

....and then run the following code in a console application:

Module Module1
Sub Main()
Dim MyDataset As New DataSet
MyDataset.ReadXml("c:\test.xml")
Console.WriteLine(MyDataset.GetXml)
Console.Write("Press RETURN to quit:")
Console.ReadLine()
End Sub
End Module

When the XML is displayed on the screen, the nested <Transaction>
element does not have the "31.21" value. Instead, that element is
imported as empty (i.e. "<Transaction />").

I understand that having the nested element with the same name as a
parent element is poor form, but I believe it's valid XML. Is this a
bug, or am I missing something obvious?

Regards,
Duane Roelands
 
I guess is a limitation on DataSets, I remember a post of somebody having a
similar problem when reading an RSS file, the answer was not to use Dataset
because of that limitation.

Good luck
Braulio

/// ------------------------------
/// Braulio Diez
///
/// http://www.tipsdotnet.com
/// ------------------------------
 
However,

If you change your xml to:

<SourceData xmlns="http://tempuri.org/SourceData.xsd">
<Transaction>
<ID>11</ID>
<Transaction>Insurance Loan Addon</Transaction>
<TransactionAmount>31.21</TransactionAmount>
</Transaction>
</SourceData>

and add a typed dataset with a "Transaction" table

and change your program to (C# equivalant)

SourceData sd = new SourceData();
sd.ReadXml(@"C:\tmp\test.xml");
Console.WriteLine(sd.GetXml());

The values come in just fine.
 
Duane

Add schema or a typed dataset definition so that ReadXml is not guessing
what the data means. This way, ID and TransactionAmount won't be string
values (which they are with your example), they will be the data type you
define.

Hope this helps
Ad.
 
Back
Top