|
|
|
start date: Tue, 21 Aug 2007 09:20:23 -0700,
posted on: microsoft.public.dotnet.framework.adonet
back
| Thread Index |
|
1
unknown
|
|
2
Braulio Diez
|
|
3
Jim Rand
|
|
4
Adrian Moore
|
Bug in Dataset.Readxml method? (Framework 2.0)
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
Date:Tue, 21 Aug 2007 09:20:23 -0700
Author:
|
RE: Bug in Dataset.Readxml method? (Framework 2.0)
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
/// ------------------------------
"duane.roelands@gmail.com" wrote:
> 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
>
>
Date:Wed, 22 Aug 2007 12:10:06 -0700
Author:
|
Re: Bug in Dataset.Readxml method? (Framework 2.0)
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.
wrote in message
news:1187713223.631125.186270@k79g2000hse.googlegroups.com...
> 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
>
Date:Wed, 22 Aug 2007 16:10:41 -0400
Author:
|
Re: Bug in Dataset.Readxml method? (Framework 2.0)
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.
wrote in message
news:1187713223.631125.186270@k79g2000hse.googlegroups.com...
> 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
>
Date:Thu, 23 Aug 2007 06:45:43 -0600
Author:
|
|
|