PC Review


Reply
Thread Tools Rate Thread

Bug in Dataset.Readxml method? (Framework 2.0)

 
 
duane.roelands@gmail.com
Guest
Posts: n/a
 
      21st Aug 2007
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

 
Reply With Quote
 
 
 
 
=?Utf-8?B?QnJhdWxpbyBEaWV6?=
Guest
Posts: n/a
 
      22nd Aug 2007
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
/// ------------------------------




"(E-Mail Removed)" 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
>
>

 
Reply With Quote
 
Jim Rand
Guest
Posts: n/a
 
      22nd Aug 2007
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.


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
Adrian Moore
Guest
Posts: n/a
 
      23rd Aug 2007
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.


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
ReadXml() method: standard DataSet vs. typed DataSet MikeOtown Microsoft ADO .NET 0 6th Dec 2007 05:15 PM
Re: does DataSet.ReadXml() clear current table information on DataSet CrunkByte Microsoft Dot NET Framework 0 21st May 2005 03:11 AM
ReadXML method =?Utf-8?B?d2lsbGlhbQ==?= Microsoft ADO .NET 2 22nd Jan 2005 03:37 AM
Question about dataset readxml method Raymond Du Microsoft ASP .NET 1 6th Dec 2004 07:13 AM
Dataset ReadXML Peter Hood Microsoft ASP .NET 1 28th Oct 2003 08:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:46 PM.