Problems with getting XML into dataset???

A

acool

I am using the following code to take a simple XML string and put it into a
dataset:

DataSet ds = new DataSet();
ds.ReadXml(new StringReader(document));

It puts the XML into a dataset alright but in transforms each and every node
into a separate table when it needs to be a row. in other words the parent
node "account needs to be the table and the nodes under it need to be the
rows. s it my XML or do I need to change my code or parameters or what??

The XML takes the basic form of:

<account><accountcategorycode name="name_1">1</accountcategorycode>
<accountclassificationcode name="name_1">1</accountclassificationcode>
<accountnumber>accountnumber_1</accountnumber>
<accountratingcode name="name_1">1</accountratingcode>
<address1_addresstypecode name="name_1">1</address1_addresstypecode>
<address1_city>address1_city_1</address1_city>
<address1_country>address1_country_1</address1_country>
<address1_county>address1_county_1</address1_county>
<address1_fax>address1_fax_1</address1_fax>
<address1_freighttermscode name="name_1">1</address1_freighttermscode>

<address1_latitude>1.0</address1_latitude><address1_line1>address1_line1_1</
address1_line1>
<address1_line2>address1_line2_1</address1_line2>
<address1_line3>address1_line3_1</address1_line3>
<address1_longitude>1.0</address1_longitude>
<address1_name>address1_name_1</address1_name>
<address1_postalcode>address1_postalcode_</address1_postalcode>
</account>
 
C

Cor Ligthert

Hi Acool,

After a long time searching, I finally was so very easy.

I hope this helps?

Cor

Serialize
using System.IO;
\\\\
StringWriter sw = new StringWriter;
ds.WriteXml(sw);
string mystring = sw.toString;
///
Deserialize
\\\
StringReader sr = StringReader(mystring);
DataSet ds2 = new DataSet;
ds2.ReadXml(sr);
///
 
C

Cor Ligthert

Hi acool,
I understand that it didn't work and I found an alternate solution.

When you do not understand code, it is good to try it, the least that can
happen is that you learn from it.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top